Lab 8 - Quicksort

Most of the code for this lab is provided for you in the lab8 directory. Create a new subdirectory for this lab on Helios. Change to that subdirectory and type the following to copy all of the files over:
cp /usr/users/mdanfor/public_html/cs223-f07/lab8/* .

File Descriptions

file_gen.cpp - This is a variation on the file generator used for the homework assignment. It generates data in the range of 0 to 999. It also seeds random with the current time instead of a static value. You can compile file_gen.cpp with make file_gen which will make an executable called file_gen
vt100ansi.h - This header file allows colors to be printed to the screen using the macro vtprintf(COLOR) where COLOR is one of the colors defined in the file.
quicksort.cpp - This defines the quicksort algorithm using median-of-three pivots. It will call insertion sort when the number of elements is less than the defined THRESHOLD value. You can run quicksort in debug mode by defining DEBUG_MODE. In debug mode, information about choosing the pivot, making the swaps and doing insertion sort are printed to the screen. Since there is a lot of information, SLEEP_SEC defines how long the debug mode pauses between stages so that the information can be read.
lab8main.cpp - This is the main program. You will need to fill in a little code to open the specified file and read the data into the local array. (Note: You will need to do a similar task to this in the current homework assignment too). To compile lab8main.cpp after making the required changes, type make main. This will create an executable called main, which can be run with main input1 or any other filename.
input1, input2 and input3 - Pre-generated input files containing 40 integers each.
Makefile - A makefile to compile the above code into executables.

Assignment

Fill in the required portion of lab8main.cpp and compile the program. Test different file sizes and see how quicksort partitions the lists. Notice how even when the list is not partitioned in the middle, the split operation still runs quickly. Turn off debugging mode by removing, commenting out or undef the DEBUG_MODE line and recompile the program with make main. Try running the following:
time main input1
This will show you how long it takes to run the quicksort executable for input1. Try generating larger files and compare the runtime. Helios is pretty fast, so you may need to increase MAX_CAPACITY to 5000 or 10000 and sort a file of that size to see a noticeable difference in the time.

Email me a small writeup (1-2 paragraphs is sufficient) of what you've seen following these instructions and your modified lab8main.cpp.