go to previous page   go to home page   go to next page

Answer:

No. insertFirst() and insertLast() insert new nodes without respect to order so they won't work for an ordered list.


Cases

various lists and various nodes

We need to write insertInOrder(int data). The data can be any int value, and the list can be any ordered list. The method needs to create a new Node and link it into the list at the right location. Exactly where that location is depends on the data and on the list.

To do this, decide on all the cases and to make sure each is handled correctly. What are the cases for insertInOrder(int data)? It is too easy to overlook a case, and also easy to be too specific. An example of overlooking a case is failing to consider inserting into an empty list. An example of being to specific is thinking that "inserting a negative value" is a separate case.

Above are some possible Nodes and three possible OrderedLinkedLists into which they should be inserted.


QUESTION 4:

What cases does insertInOrder(int data) need to handle?


go to previous page   go to home page   go to next page