Objectives and Overview: A priority queue is a queue whose elements are removed in order of their "priority" rather than the order in which they arrived. This strategy for removal allows elements to "jump ahead" of other elements that had arrived earlier. The "heap" is a convenient way to implement a priority queue, since its smallest element is always the root. This lab explores the use of heaps to implement priority queues. It asks you to write a heapSort method which is outlined on page 222 of your text. You should read up through section 12.4.2 in Chapter 12 of your text before doing this lab.
On the CS210 (Tucker) server are five files that you should drag to the desktop: sortDriver2.java, VectorHeapSort.java, VectorMergeSort.java, Assert.java (that's in the Source folder), and Structure.zip. Build a project called Lab8yourname.µ that looks like the one below:
Now run this program to sort, say, 10 integers using the mergeSort for which it is currently set up. Notice that there's a commented-out call to a heapSort method which has not yet been implemented. That is, if you commented out the mergeSort call instead, the heapSort will not do any sorting of the Vector data; it will just return the original values untouched.
Your main task in this lab is to complete the heapSort method whose skeleton is provided inside the VectorHeapSort.java file. You should consider using the VectorHeap implementation of priority queues, so that integers removed will appear in sorted order.
Test this new method using the SortDriver2 program to be sure that it works properly.
Using a slightly different run of this program for the input If a woodchuck could chuck wood (without the exclamation mark at the end), answer the following quesitons:
Submit your Java program from Part 2 of this lab by dragging it to the Drop Box folder. Also hand in a hard copy listing of your program, along with your answers to the questions in Part 3.
Feel free to work on the programming part of this lab individually or in teams of two. But please complete the answers to the questions in Part 3 individually.