A question asking you to delete the middle node in a linked list, only that node is give.
The way to solve the problem is copy middle.next.element
to middle.element
and then delete middle.next
by doing middle.next=middle.next.next
There's a special case which is when middle.next is the last node. The answer say that you could mark the middle node as dummy.
I'm not familiar with the idea "dummy". How to mark a node as dummy and how to use a dummy node in other cases?
What about dummy data in general?
null
, so if the second-to-last node (the last real node) is deleted, you do not have to backtrack to the node before that, to change that node'snext
element. – Anemone