java.lang.Object | +--HeapSort
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 |
public HeapSort()
Method Detail |
public void sort(java.lang.Object[] arrayToSort, Comparer comparator)
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.