Linked List Of Ints: Add to Front

advertisement
Adding To The Front Of The List
The goal for this exercise is to create a simple Linked List Node class, and use it to
create a simple linked list class of your own.
For this exercise, you need to implement the AddToFront method in the
provided MyIntList class, as well as any other methods that you need to implement in
order to accomplish the goal of implementing AddToFront. This class should be found
in the Student_Answers.cs file in a project named something like
03_PCE_StudentCode.
In the class named IntListNode, you should add a constructor which takes
as an argument an int that it will store.
Next, implement the AddToFront code that will add a single item to the front of
the linked list that was created in main. Write code to do that once, then use the
debugger to ensure that everything's gone smoothly (if you're familiar with the
debugger).
Then make sure that you can write code that be used to repeatedly add items
to a list. You might start by figuring out what you need to do in order to add a single
item to the front of the list, and writing the code to implement that. Next, you should
figure out how to write your code so that you can add items in the list by repeatedly
executing the same code. For example, if you put your code in the following loop, you
should be able to add 3 items to the list:
for(int i = 0; i < 3; i++)
{
objectIDeclared.AddToFront(3);
}
the major implication of this is that you'll need to ensure that things like your reference
to the first item in the list is properly updated, so that at the end of each loop, it
points (refers) to the first item in the list.
Once you’ve done this, make sure that all the tests in the
NUnit_Tests_LL_AddToFront class pass.
What you need to do for this exercise
1. Implement the IntListNode’s constructor, as described above
2. Implement AddToFront, as described above
3. Once you’ve completed the above task, you should run the tests in the
NUnit_Tests_LL_AddToFront 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