Deleting first node in linked list has problems

前端 未结 3 1589
鱼传尺愫
鱼传尺愫 2021-01-25 10:05

I\'m implementing a linked list and it needs to have a function that when given a head of a linked list and a cstring, it finds and deletes a node whose value is the cstring.

3条回答
  •  死守一世寂寞
    2021-01-25 10:50

    You construct a list by pointing to the first node.

    Then you delete the first node, but do not update the pointer to the list to point to the second one

    Just make your function check if you are deleting the first node, and always return a pointer to the first pointer of the final list. Alternatively, instead of node *root parameter, pass node **root so you can modifiy the reference in your function (although I don't like this way of working).

提交回复
热议问题