Linked List Of Ints: Traversing

advertisement
Traversing The List
The goal for this exercise is to add a Print method to your simple Linked List class,
in order to gain experience with algorithms that traverse a linked list.
For this exercise, you need to implement the PrintAll method in the provided
class, as well as any other methods that you need to implement in order to
accomplish the goal of implementing this method. This class should be found in the
Student_Answers.cs file, in a project named something like 03_PCE_StudentCode.
MyIntList
The ‘PrintAll’ method should iterate through all the nodes, one at a time, and
call the Print method on each one. (Obviously, if your LinkedListNode class doesn't
yet have a Print method, you'll have to add one). The print method for each node
should print out a single line, that contains only the number (the Data) that the node is
storing. Because PrintAll should call this method on each object in sequence, the
correct output calling PrintAll on a list that contains {1, 2, 3} should be:
1
2
3
Hint: Start at one end of the list, and continue to loop while your reference isn't
null, printing as you go.
Once you’ve done this, make sure that all the tests in the
NUnit_Tests_LL_PrintAll class pass. Note that these tests make use of your
AddToFront method, and assume that AddToFront is working correctly. If your
AddToFront is not working correctly, then the tests for the PrintAll method may (or
may not) be giving you true answers. In other words, if your AddToFront doesn’t work,
then a test failing (or passing) in the PrintAll tests may or may not really be failing (or
passing)
What you need to do for this exercise
1. Implement PrintAll, as described above
a. Implement anything required by PrintAll
2. Once you’ve completed the above task, you should run the tests in the
NUnit_Tests_LL_PrintAll class. They should all pass at this point, and if not, then
you should fix your program so that those tests do pass. You can run the tests
using the NUnit support in the provided starter project. You should feel free to
supplement that code with your own test cases if you wish, but you are neither
required nor expected to.
Download