Note that the test program uses some of the command codes differently than in the last lab. Type an illegal command to see what the codes are.
This lab involves advance preparation.
In ~csci102b/labs/lab7 is some code for manipulating lists:
Here is the header and comments:
// dupList // PRE: list is a well-formed list // POST: returns a list which duplicates all the elements from list // e.g., if list = (3 7 2), the routine returns (3 3 7 7 2 2) // list' is undefined. // Node * dupList (Node * list);
Some more details: duplicating a list with no elements, gives you a list with no elements.
The parameter is passed by value, because we're returning the updated list. But here, since the first pointer never gets changed, this function will always return its parameter. The test program calls it as follows:
theList = dupList(theList);
Here is the header and comments:
// splitAt // PRE: theList is a well-formed list // POST: if value occurs somewhere in theList // l1 is a list elements from theList that occurred before first // occurrence of value. // l2 is a list of elements from value to the end of theList. // if value doesn't occur in theList, // l1 has all the elements from theList // l2 is empty // Original order of elements is maintained. // theList' is empty. // Ex1: BEFORE call theList: (5 10 15 20 25) value: 15 // AFTER call l1: (5 10) l2: (15 20 25) theList': <empty> // void splitAt (Node * &theList, int value, Node * &l1, Node *&l2);
Note that one or both of the resulting lists (l1 and l2]) may be empty after the call, depending on where we're splitting. Its also legal to call it with an empty theList.
Your implementation must not create or destroy any nodes (i.e., all nodes get "recycled" from theList).
Show the t.a. your prepared code and test data for each of the two problems (one point for each). You will get the checkoff point if your code is reasonably close to correct, and your test data tests all cases.
Demonstrate for and show to the t.a. your correct solution to the problem. Run it on all your test cases.