Insert A New Node In Order
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:
- For this exercise,
you need to implement the
InsertInOrder method in the provided MyLinkedList class.
- 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.
- The InsertInOrder method looks like:
void InsertInOrder(int newData);
This version of the insert
method should insert a new item in the linked list, in ascending order. In
other words, if you've got the values {1, 3, 9} stored in the list (in that
order), and you want to add the value 4, this method will do whatever it needs
to in order to ensure that the value in the list (listed here in the same order
that their nodes appear in the linked list class) would be {1, 3, 4, 9}.
- Annotate this method (put a comment next
to this method) describing the running time of that method, using the Big "Oh"
notation.
- Once you’ve completed the above task, you should run the tests in
the
NUnit_Tests_LL_InsertInOrder
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.
- NOTE: There are tests for this exercise. HOWEVER, if this
exercise is not marked 'Hand In' on the page for this Lesson then
you are not required to make these pass.
It's good practice.
And it's recommended
But it's not required.