|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectHeapsort
public class Heapsort
The Heapsort Java application illustrates a heapsort.
Part of the implementation (the makeHeap and
reheapifyDown methods) is left
as a student exercise.
makeHeap and reheapifyDown:
| Constructor Summary | |
|---|---|
Heapsort()
|
|
| Method Summary | |
|---|---|
static void |
heapsort(int[] data,
int n)
This method cannot be used until the student implements makeHeap and reheapifyDown. |
static void |
main(java.lang.String[] args)
The main method illustrates the use of a heapsort to sort a small array. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Heapsort()
| Method Detail |
|---|
public static void main(java.lang.String[] args)
String arguments (args) are not used
in this implementation.
public static void heapsort(int[] data,
int n)
makeHeap and reheapifyDown.
Sort an array of integers from smallest to largest, using a heapsort
algorithm.
data - the array to be sortedn - the number of elements to sort, (from data[0]
through data[n-1])
data has at least n elements.
n is zero or negative then no work is done. Otherwise,
the elements of data have been rearranged so that
data[0] <= data[1] <= ... <= data[n-1].
java.lang.ArrayIndexOutOfBoundsException - Indicates that data has fewer than n elements.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||