when working out what to do with linked lists here's a technique I use to help: draw a diagram of what I am trying to do before I write the code. For a singly linked list I use two lines to represent a node like this:
node name
pointer
and use an extended arrow to represent which node is being pointed to.
Code:
Say I start with this:
previous
next------------>current
next------------>currentNext
next
with goal being to delete current node of a singly linked list and end up with this:
previous
next------------->currentNext
next
//steps
previous->next = current->next;
delete current;
It's easier for me to get the reassignments correctly if I see what I am doing. For what it's worth.