Class HeapSort

java.lang.Object
  |
  +--HeapSort

public class HeapSort
extends java.lang.Object

This class represents an "algorithmic object". An instance of this class contains a single method called sort() that implements the heapsort algorithm on an input array using a comparator that is also passed as a parameter.

Notice that the method sort() is an instance method. I don't know if there is any real advantage to implementing sort() this way, instead of making it a static method. But the technique used here seems to be common with libraries of generic algorithms.


Constructor Summary
HeapSort()
           
 
Method Summary
 void sort(java.lang.Object[] arrayToSort, Comparer comparator)
          Implement heapsort.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HeapSort

public HeapSort()
Method Detail

sort

public void sort(java.lang.Object[] arrayToSort,
                 Comparer comparator)
Implement heapsort. This method will run in O(n*ln(n)) time.

Parameters:
arrayToSort - This array will be copied into and then out of a heap to implement heapsort.
comparator - A comparer object that implements the order that we wish to sort with respect to. Notice that any input array can be sorted in different ways by defining different Comparer classes for the objects in the input array.