C programming Linked Lists delete node at position N

前端 未结 5 546
猫巷女王i
猫巷女王i 2020-12-18 08:16

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

5条回答
  •  -上瘾入骨i
    2020-12-18 08:50

    Removing a given node n from a singly-linked list can be boiled down to this operation:

    • Set the pointer that points to n to point instead to n->next.

    You can break this down into two operations:

    • Find the pointer that points to n;
    • Set that pointer to 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.

提交回复
热议问题