CIS 501
Spring, 2003
Assignment 05p - Preliminary Assignment
- Write a C++ function to insert a data item (called item) into a sorted (ascending order) array first_names of string values. The array should remain sorted after the insertion. Be sure your function contains all the requisite precondition and post condition statements and appropriate comments.
- Write the test driver program for this function. Your test driver should print the array before the insertion and after. The function should return a flag indicating whether or not the insertion was successful. The value of the flag should also be printed. Be sure to test your program for the following cases.
- array empty
- insertion done at front of array
- insertion done at back of array
- insertion done in the middle of the array
- array already full
- Now write a C++ function to insert a data item into a sorted single linked list. The list should remain sorted after the insertion. Be sure your function contains all the requisite precondition and post condition statements and appropriate comments. The function should return a flag indicating whether the insertion was successful or not. Use a modified version of the same test driver developed in part 2 (the arguments may be a bit different as the head pointer to the linked list should be the only argument you need to pass). Be sure your driver program also tests for all cases. Note that this function will be useful in Assignment 5.
Due Date: To be determined.