CSC 220 Lab 9 - Heap Sort

Tuesday, October 26, 2004

Exercises

Write a Java program that sorts the elements of the following arrays using a heap sort algorithm, implemented as we discussed in class using a priority queue. You can use the HeapPriorityQueue implementation provided with the textbook code (the source and compiled Java files are in the M:\classes\cs220\net" directory on the computer lab machines).

Your program should sort the arrays both in ascending and descending order (you achieve this by providing a proper Comparator object to the priority queue constructor).

The arrays to sort are:

         int[] A = {8, 56, 7, 34, 5, 67, 9, 88, 12, 33, 120, 100, 42, 3, 16};
         String[] B = {"stack", "heap", "chain", "tree", "queue"};
    

Hand in

Hand in a printout of your program file and also submit it online through VikingWeb.

 


Last modified: Mon Oct 25 15:10:27 EDT 2004