The answer to some of the design questions depends on what the list is expected to be used for. But reasonable answers are:
value
is not in the list? Return true or false for item deleted or not.value
? Delete only the first instance.current
and next
) needed? Yes. The logic is similar to case IV.The pictures show two situations.
Two pointers traverse the list, one behind the other, until the leading pointer (next
)
encounters the node to be deleted.
Then that node is unlinked from the node current
points to.
With insertInOrder()
had four cases.
What cases are there with delete()
(not all are shown in the picture)?