Homework 8 - Heapsort (Extra Credit)

Due: Tuesday June 7, 2011 at 5:00pm

This is an extra credit assignment. No late submissions will be accepted. The code for this assignment will not be on the final, BUT the *concepts* may be on the final.

The purpose of this assignment is to implement an array-based heap data structure and the associated heapsort algorithms. This assignment specifically implements a max-heap.

For this assignment, you will be making an array-based heap structure that will contain an array of elements, the count of elements in the array and the capacity of the array. The array should be a dynamic array so that it can be adjusted to fit arrays of different sizes. So the capacity will reflect how many elements were allocated to the array by the new command. This data structure will be passed to (or created by) the various algorithms associated with heaps and heapsort.

You will define the following functions:

Your main function will take two filenames from the command line (similar to the mergesort assignment). The first filename will be the input file containing the original array. The second filename will be the output file for outputting the sorted array. Read the data from the file into an array local to main. Call the heapsort function, passing it the array. After heapsort returns, output each element of the array (which should be sorted) to the output file.

Email the source code to me. If you cannot finish the assignment by the due date, email me what you have completed for partial credit.