Class Heapsort

java.lang.Object
  extended by Heapsort

public class Heapsort
extends java.lang.Object

The Heapsort Java application illustrates a heapsort. Part of the implementation (the makeHeap and reheapifyDown methods) is left as a student exercise.

Java Source Code for this class (without makeHeap and reheapifyDown:
http://www.cs.colorado.edu/~main/applications/Heapsort.java


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

Heapsort

public Heapsort()
Method Detail

main

public static void main(java.lang.String[] args)
The main method illustrates the use of a heapsort to sort a small array. The String arguments (args) are not used in this implementation.


heapsort

public static void heapsort(int[] data,
                            int n)
This method cannot be used until the student implements makeHeap and reheapifyDown. Sort an array of integers from smallest to largest, using a heapsort algorithm.

Parameters:
data - the array to be sorted
n - the number of elements to sort, (from data[0] through data[n-1])
Precondition:
data has at least n elements.
Postcondition:
If 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].
Throws:
java.lang.ArrayIndexOutOfBoundsException - Indicates that data has fewer than n elements.