In quick_2_sort.cpp, you implement Quicksort, choosing the partition as the median of the first, middle and last element. When the size is two, you do not partition, but just sort the two elements by hand. See the lecture notes for how I calculate the middle element.
To compile and test, copy the files sort_driver_lab.cpp, sorting.hpp and makefile from the sorting lecture note directory. On the EECS machines, these are in the directory:
/home/jplank/cs302/Notes/Sorting |
If you type "make clean ; make lab", it will compile your merge_1_sort.cpp and quick_2_sort.cpp with sort_driver_lab.cpp, and create the executables merge_1_lab_sort and quick_2_lab_sort. You can use the executables in the sorting lecture note directory to test yourself. Those are the ones against which your programs will be graded.
Make your output match mine exactly. See the lecture notes for detail on the output of the two programs.
Whenever you use a seed that is a multiple of 2000, the driver program will produce vectors with lots of duplicate entries.
To help with this, there is a program called quick_2_stdin, which runs on standard input. That way, you can see how to handle the six cases. For example:
UNIX> echo 0 2 3 4 1 6 7 8 1 | quick_2_stdin | head -n 2 S: 0 9 0.00 2.00 3.00 4.00 1.00 6.00 7.00 8.00 1.00 M: 0 9 1.00 1.00 2.00 3.00 4.00 1.00 6.00 7.00 8.00 0.00 UNIX>