CIS-3050 Homework #2: Generic Programming in C

Due: Wednesday, September 7, 2016

Study the way the generic insertion sort algorithm was implemented in the provided samples (compare it to the specialized implementation that can only sort integers).

  1. Add a new header file to the ADS project called Mutators.h. This file will declare functions that mutate, or modify, the arrays they are given but that are not sorting algorithms. In this header declare a function reverse_array as follows:

            void reverse_array( void *first, size_t element_count, size_t element_size );

    The purpose of this function is to reverse the order of elements in the array. For example and array such as [1, 2, 3] would be transformed by this function to the array [3, 2, 1].

  2. Add a new source file to the ADS project called Mutators.cpp. In that file implement the reverse_array function. Be sure your function can reverse an array of any element type.

  3. In the UnitTests project copy the file SortersTests.cpp to a new file named MutatorsTests.cpp. Modify the file by changing the name of the TEST_CLASS appropriately and deleting unnecessary material. Using the TEST_METHOD InsertionSort as a base, write a TEST_METHOD named ReverseArray that does some basic testing of your function. Verify that the tests pass.

Submit your files Mutators.cpp and MutatorsTests.cpp in a zip archive.

Last Revised: 2016-08-23
© Copyright 2016 by Peter C. Chapin <>