EDIT: Figured out the problem. Also if you found this through google or another search engine here is where I went wrong and how to fix it.
My delet
Removing a given node n
from a singly-linked list can be boiled down to this operation:
n
to point instead to n->next
.You can break this down into two operations:
n
;n->next
.The complication arises because the pointer that points to n
might either be the p->next
field of the previous node in the list, or the head
pointer (if n
is the first node in the list).
Your code does not appear to be complete - it doesn't ever set the ->next
field of any node to anything, so it's hard to say what's actually wrong.