Development tools

For this lab you will create a simple selection sort program in C. This assignment is practice of effective development practices:

You should checkin your progress after each step. You can use git commit -a to commit all changes since your last commit. This can save time if the changes are small.

  1. Pull your course repository.

  2. Create a branch to contain the feature we will develop. Call the branch simplesort. The command git branch XYZ will be helpful. Read the man page if you need. Checkout the branch after you create it.

  3. Open Visual Studio (or your IDE of choice). Create a project in the simplesort directory. Your source files must go in the root of the directory. If you use Visual Studio:

  1. Create a file called sort.c. Go to Project > Properties > Linker > System and set SubSystem to Console.

  2. Add this to the top of your sort.c file:

     int size = 10;
     int array[] = {-7, -32, 20, -2, 14, 5, -1, 13, -22, 23};
  3. Create a main function in the standard C style. Remember that any functions that main calls need to be defined above main.

  4. Create an empty function called void testMax(). Call this function from main. This function should test a function you will create in the next step: getMaxId. getMaxId takes an array and a size and returns the index of the maximum element.

  5. Add an include for the assert.h header. Complete the testMax() function, using assert and a loop to verify you found the maximum element id. You may stub in getMaxId() if you wish. Assert tests look similar to this:

     assert(array[max] >= array[i]);
  6. Add a function getMaxId() that takes an int array, its size, and returns the index of the maximum element. Verify your function is correct using your test.

  7. Add a function testMaxAtEnd(). This function will test maxToEnd() which will swap the maximum element to the last position in the array. You should again use asserts to verify correct operation.

  8. Complete the function maxToEnd(). This function takes an array, its size, and finds the maximum element. It then swaps this element to the last position in the array. Verify your function is correct using your test.

  9. Add a function testSort(). This function will test sort(). Again, use loops and asserts to verify the array is sorted.

  10. Complete the function sort(), which takes an array and an upper bound. The function should swap the maximum element to the end of the array, then repeat on the same data but with bounds size smaller by one. This is basically selection sort. Verify your selection sort is correct using your test.

  11. After your final commit, merge your changes back to the main branch:

  1. Complete the assignment:
    • Open repo and show all branches visually (use gitk --all)
    • Open your sort.c file.
    • Ask your instructor to verify the assignment.