LinkList Pointer
I have a linklist A->B->C->D my head pointer is on A i want to delete node c with only one head p开发者_StackOverflowointer. i dont want any code just explanation.
Delete node C and make B->next to D.
When traversing the list you probably want to store the previous node in a variable, so when you hit C, you set the prev node's (which is B) next to D.
You walk the list, keep both the node you are currently looking at, and the previous one. When you find the node you want to delete, you change the link in the previous node to point to the next node.
You need to special case if you end up wanting to delete the head node as well.
Two steps
1 Update next link of the previous node, to point to the next node, relative to the removed node. in your case, you need to set B link to D
2 Dispose removed node.
精彩评论