Lab 8 - Quicksort

Due: Wednesday at 5:00pm
This lab is worth 10 points.

Most of the code for this lab is provided for you in the lab8 directory. Use the following command to create a lab8 subdirectory off your current directory:

cp -r /usr/users/mdanfor/public_html/cs223-s08/lab8/ .
The -r option to cp is what will create the lab8 subdirectory and copy all the files over to it.

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_USEC defines how long the debug mode pauses between stages so that the information can be read. You can turn this pausing off by defining SLEEP_USEC as 0.
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. This is needed for the make commands to work.

Misc. Notes

This works best if you are using a color terminal with scrollback capacity. If using the machines in 407, issue the following command to launch a nice color-enabled terminal with scrollback:
rxvt -rv -ls -sl 1000
The -rv option will do reverse video which will swap the background and foreground colors. So if your normal terminal in 407 has a white background with black text, -rv will launch rxvt with a black background and white text. The -ls option will source your .profile file on Helios, which is what sets up the blue and green prompt that tells you what directory you are in currently. The -sl 1000 option will set the scrollback buffer to 1000 lines.

If you are using your laptop instead of the machines in 407, make sure that your terminal supports VT100 ANSI colors. Putty for Windows should work, as should the Mac OS X terminal. The pausing code may behave oddly if you try to download it and compile it on Windows (even though there is a workaround in the code, Windows does poorly with this sort of task), so make sure to log into Helios and try the code there.

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 undefining 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. You can try this for all the files you've generated for this lab. However, Helios is pretty fast, so you may not notice much of a time difference with the defined MAX_CAPACITY.

Email me your modified lab8main.cpp.