Source of 26.20.java


  1: public static <T extends Comparable<? super T>>
  2:        void heapSort(T[] array, int n)
  3: {
  4:    // Create first heap
  5:    for (int rootIndex = n / 2 - 1; rootIndex >= 0; rootIndex--)
  6:       reheap(array, rootIndex, n - 1);
  7: 
  8:    swap(array, 0, n - 1);
  9: 
 10:    for (int lastIndex = n - 2; lastIndex > 0; lastIndex--)
 11:    {
 12:       reheap(array, 0, lastIndex);
 13:       swap(array, 0, lastIndex);
 14:    } // end for
 15: } // end heapSort
 16: // Version 4.0