/** * Class: HeapSortDemo * Author: Peter Williams * LastEdit: Mon May 19 17:12:03 2003 * Purpose: To demonstrate the use of heap sort */ import DataStructures.*; import java.util.*; public class HeapSortDemo { static final int max = 24; public static void main(String[] args) { Random r = new Random(); Comparable[] array = new Comparable[max]; int n = max / 2; for (int i = 0; i < n; i++) { array[i] = new Integer(r.nextInt(1000)); } System.out.print("random:"); for (int i = 0; i < n; i++) { System.out.print(" " + array[i]); } System.out.println(); long t1 = System.currentTimeMillis(); Sort.heapSort(array, n); long t2 = System.currentTimeMillis(); System.out.print("sorted:"); for (int i = 0; i < n; i++) { System.out.print(" " + array[i]); } System.out.println(); System.out.println(); System.out.println("That took " + (t2-t1) + " milliseconds"); } }