LL: Remove by value, in order

advertisement
Remove A Node By Value
The goal of this exercise is to make sure that you can implement the logic needed to
add items to the middle of a linked list (based on the value of the item itself, rather
than a predetermined position).
What you need to do for this exercise:
1. For this exercise, you need to implement the RemoveByValue method in the
provided MyLinkedList class.
a. This class should be found in the Student_Answers.cs file, in a project
named something like 03_PCE_StudentCode. In the starter project, in the
OO_Linked_List project, you'll find a class named MyLinkedList.
2. The RemoveByValue method looks like:
ErrorCode RemoveByValue(int value);
When this function ends, the first node that contains "value" should be removed
from the list. If no nodes contain “value”, then return something like "NotFound"
(you may have to define this return code yourself). If more than one node contains
"value", you only need to remove the first one.
a. You are NOT allowed to assume that the nodes will be in any particular
order. Specifically, the nodes may (or may not) be in ascending order.
b. If the value that you’re asked to remove is not present in the list, then the
list should be left unchanged.
3. Annotate this method (put a comment next to this method) describing the running
time of that method, using the Big "Oh" notation.
4. Once you’ve completed the above task, you should run the tests in the
NUnit_Tests_LL_RemoveInOrder 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.
a. Test cases include:
Delete from an empty list (i.e., a list that contains no nodes)
Delete from a single-item list
Delete from a two-item list
Delete from a multi-item list
b. Be aware that these tests may use functionality not explicitly required above
(for example, the tests may make use of the InsertAtFront/AddToFront
method). If these other functions are not properly working, then these tests
may or may not reliably pass.
Download