+ 2
Multi linked list
How to delete a node from a list
1 ответ
+ 2
assuming the linked list is
a -> b -> c -> d -> e
if you want to delete node c
just do this:
>>> b.next = b.next.next
the "next" property restore the next node
so before you do this
"b.next" is "c"
and "b.next.next", also "c.next", is "d"
then we want "b.next" to restore "d", and it is "b.next.next"
therefore, we do this:
>>> b.next = b.next.next
now, b is linked to d, and c is missed unless you have stored it with another variable