CS 2213 Advanced Programming, Spring 2001 Programming Assignment 1


Due In Class, March 1, 2001

In this assignment you will finish the implementation of the Heap Sort that was started in class.


Part 0: Writing and testing the program

Create a directory called assign1 for this assignment.

Copy all of the files from /usr/local/courses/cs2213/spring2001/assign1 into this directory. You should have 4 files: a makefile, a source file (.c), a header file (.h) and an object file (.o).

Insert your printTree15 function from Lab Assignment 2 in the appropriate place in heapsort.c. We will be using this instead of the printTree discussed in class. You have three additional functions to write.

Create a file called heaptest.c which will contain a main function for testing your program.

Use the makefile to run lint on your program.

Start testing by using the example from class. Make an array of size 15 and fill the first 10 elements with the example from class. Fill the rest of the array with -1.

Call insertOneInHeap a few times, printing out the tree with printTree15 after each call.

When you think this is working, you can call makeHeap directly.

Now do the same thing with sortHeapOne and sortHeap.

Use checkSorted to make sure the sort worked correctly.

When you think everything is working correctly, use getRandomArray to create an array of size 10,000 and call makeHeap, sortHeap and checkSorted.

Save some output from each of your tests so that you can hand it in.

Part 1: Handing in the programs

One of the files you have should be heaptester.o. When you run make it will create an executable called heaptester. Run this program and save the output generated. Print it out and include it with the packet you hand in. This program will print out a table giving the time to sort each of 4 tests. The values should be consistent with an order nlogn sort. If your algorithm is correct, the last line of output should say congratulations.

You will be handing in the following:

You will consecutively number the pages of your printout and put the page numbers of the various parts on the cover sheet. Be sure to fill in the cover sheet completely.

Staple everything together in the upper left corner and hand it in in class on the due date. Do not use any kind of envelope or folder.