CS 14 - Lab


CS 14 Homepage

Templatized Insertion Sort


You will be writing a templatized version of the insertion sort sort algorithm. You will then use your sorting function to sort arrays of ints, floats, chars, and a user defined class (obtainable here). The user defined class will consist of a first name and a last name string. Instances of the class will be sorted by last name and then by first name. You will need to overload one or more operators to accomplish the sorting of the class instances.

You will also need the print functions obtainable in print.cc. Please note that I could have used a template function instead of giving you 4 different instances of the print function, one for each type sorted. .5 extra credit points will be available for replacing the print function with a templatized print function and implementing any necessary overloaded functions to acheive this.

Note about template functions and g++

To comply with good coding style, you should assume that when creating your template functions, they should go in a separate file other that where your main function is in main.cc. However, due to the implementation of gcc/g++, template functions must appear in the file that has the function call to those functions. This is not the norm, just happens to be how gcc/g++ was implemented. You will find that different compilers will not have this problem. If you had a template class with template functions, those could all go in a header file. However, since you are just writing template functions, don't put them in a header file. Instead, you may put your templatized function(s) before the main function in my main.cc file. The TA will then have to visually check the main function to verify that you have not altered the functionality testing.

Point Breakdown For Lab Assignment

Please show the output from main.cc to the TA if. The TA will also look at your code for correctness when checking out. Remember, to receive credit for this lab, you MUST turn the code in online as well as demo in lab, however, you will only receive points for what you demo to the TA during lab section. If you do not turn in your code online, you will lose points for your lab. All code must be turned in online for archival purposes. Remember to put both partners names on the code that you turn in.

Remeber to compile your code using the flags "-g -Wall -W -Werror -pedantic". You must use a makefile.