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

前端 未结 24 1341
陌清茗
陌清茗 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:04

    The initial suggestion was to transform:

    a -> b -> c

    to:

    a ->, c

    If you keep the information around, say, a map from address of node to address of the next node then you can fix the chain the next time to traverse the list. If need to delete multiple items before the next traversal then you need to keep track of the order of deletes (i.e. a change list).

    The standard solution is consider other data structures like a skip list.

提交回复
热议问题