Deleting a middle node from a single linked list when pointer to the previous node is not available

前端 未结 24 1164
陌清茗
陌清茗 2020-11-29 20:42

Is it possible to delete a middle node in the single linked list when the only information available we have is the pointer to the node to be deleted and not the pointer to

24条回答
  •  有刺的猬
    2020-11-29 21:15

    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.

提交回复
热议问题