You are on page 1of 1

-1-

Problem
Compute insertion, quick, merge and heap sorts on an array of pseudorandom integers and
report the running times.
Input
A set of n integers with values in the range [1, RAND_MAX]. The value must be input in the
command line in argv[1].
Output
A table listing the running times of each sort on an array in which the elements are arbitrarily
arranged and on an array in which the elements are pre-sorted in non-decreasing order.
Program criteria
1. The program must start with a greeting message explaining the program. The greeting must
pause, then prompt the user to press a key to continue.
2. Create the array(s) and populate std::rand().
3. Display a menu having these choices.
a. Sort random array and sorted array on all 4 sorts.
b. Sort random array and sorted array on 3 sorts (quick, heap, and merge).
c. Sort random array only on all 4 sorts.
d. Sort random array only on 3 sorts (quick, heap, and merge).
e. Display the original array and the sorted array on all 4 sorts.
4. Run the chosen sorts then display the results in a table similar to the following. Make sure
your columns align on the left edge.
Time (in seconds)
Sort Random Sorted
Quick 0.0000 0.0000
Heap 0.0000 0.0000
Merge 0.0000 0.0000
Insertion 0.0000 0.0000
Notice that the times have a precision of 4 places.
5. The input to each sort must be an identical array (same elements, in same order).
6. You must use the pseudocode for each sort as listed in the textbook.
7. Program style will include the following: Whitespace, indentation, header comments in each
file (see sample program), symbolic constants (no literals), code comments where
appropriate. The header comments in the driver file should describe the program. Header
comments in other files should describe the purpose of the file. Code comments should be
brief and simply describe what a particular block of code is doing. Use descriptive names
for functions, variables, constants, etc, then commenting will be minimized. Notice that
style also includes error checking on the input (what if the user types in -1 for the array
dimension?). The main function should be SHORT. It should generally, just call top-level
global functions.
8. If the user chooses to display the elements, format them so that there is a field width of 7 for
each number, and 8 numbers per line (with the possible exception of the last line).

You might also like