CS302 -- Lab 6 -- Sorting

Quicksort and Merge Sort

Your job is clear -- write quick_2_sort.cpp and merge_1_sort.cpp from the sorting lecture notes.

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.

Make your output match mine exactly. See the lecture notes for detail on the output of the two programs.

Make sure you use the driver program from this directory -- it is like "sort_driver_lab.cpp" in the lecture notes, where seeds that are multiples of 2000 will produce vectors with lots of duplicate entries.

A note on quicksort and duplicate entries

You'll note that there are six cases of duplicate entries for which I haven't specified what you should do with the pivots. These are when two of the three candidates for the pivot equal each other, and the third doesn't. This has caused students consternation in the past. 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