CS 302 Assignment 4: Counting the Number of Comparisons of a Sorting Algorithm (Part 2)

Due date: Thursday, October 1, 2009, midnight.

All programming assignments must be submitted electronically. Submit them to the graduate assistant, Abhinav Dasu, by email at
dasun"at"unlv"dot"nevada"dot"edu
on or before the due date. Your email must come from your engineering college (or computer science or computer engineering) account.
Write a program which
  1. Reads real numbers from a file into an array of size no more than 1000, and reports the size of that array.
  2. Sorts the same array using mergesort.
  3. Sorts the same array using quicksort.
  4. Sorts the same array using heapsort.
  5. Counts the number of comparisons for each of the three sorting algorithms, and reports that number.
  6. You may work this assignment by starting with the code that you wrote for Assignment 2 and modifying it appropriately.


Use the following two files to test your program:
a small file
a large file
a file that is "almost" sorted
another file that is almost sorted
a very dangerous file