next up previous
Next: What to turn in Up: Assignment 3: Lists Previous: Set up List

Add more methods to the List class

1.
Do exercise 1 on page 90 of the book (Section 3.5). Add some code to main that tests the new method.

2.
Do exercise 2 and test the new method.

3.
Do exercise 3, with the following modifications. I don't like the book's use of capital letters for variable names. Please use node for the node that is already in the list, and newNode for the one being added. Also, please call the method insertNode.

4.
Do exercise 4, except don't call it clone. Call it copy instead. You can do it either iteratively or recursively. I found it easier to do recursively. Here is a hint about how to do that. Write a method called copyNodes that is a class method in the ListNode class. It should take the first node in a list as a parameter, and it should return a new list of nodes.

5.
Do exercise 5. Again, I found it easiest to do this by writing a recursive class method in the ListNode class named reverseNodes.

6.
Do exercise 6. You should type in the code and provide an example that causes the code to fail. Then fix the problem.

7.
Do exercise 8. Again, type in the code and provide an example that causes the code to fail. Then fix the problem.

8.
In the original version of main, the comments indicate that I don't like the way we are building the list. Replace the evil code with something more elegant. You will probably want to use the new methods you just wrote.


next up previous
Next: What to turn in Up: Assignment 3: Lists Previous: Set up List
Allen B. Downey
1999-09-23