Delete a node in singly link list

后端 未结 3 1632
臣服心动
臣服心动 2021-02-03 12:21

How to delete a node in a singly link list with only one pointer pointing to node to be deleted?

[Start and end pointers are not known, the available information is poin

3条回答
  •  渐次进展
    2021-02-03 12:39

    Not possible.

    There are hacks to mimic the deletion.

    But none of then will actually delete the node the pointer is pointing to.

    The popular solution of deleting the following node and copying its contents to the actual node to be deleted has side-effects if you have external pointers pointing to nodes in the list, in which case an external pointer pointing to the following node will become dangling.

    You can find some discussion on SO here.

提交回复
热议问题