Lab 6: Heap Sort

Due Date and Submission Requirements


The goal of this lab is:


Directions

Download Lab6Demo.Java as a starting point. You will write the HeapSort class (provided below), which will contain a method called heapSort(). This method must implement the Heap Sort algorithm that was discussed during lecture on 3/4. This method will return a sorted array. This class implements an interface, which makes your write the required methods for this lab. Given an unsorted array of integers, heap sort first constructs a Max Heap from the array. This will involve doing a for loop backwards through the array, and swapping the node with it's children if a child is larger than it.

Once the heap is created, the sorting can begin. The root node is swapped with the last element in the heap, and the new root is heapified down to its correct location. This process is repeated N times until the array is sorted (see lecture).

You must use a Max Heap like we did in class. Your heap sort algorithm must also be an in-place sorting algorithms, which means you must only modify the orginal array (you are not allowed to create a new array).

Your solution must include the following methods, and these methods must be used somewhere in your heap sort algorithm: You will likely have more methods, but those methods are what's required.

Starting Code

Required Output

The output of your program should look exactly like this output. Your program should sort the integer array from least to greatest.

Grading (10 points)

NOTE: If your code does not compile, correctness cannot be verified, and you won't receive any points for your code. Turn in code that compiles!