File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Sprint-2/implement_linked_list Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -42,5 +42,28 @@ def pop_tail(self) -> any:
4242 return node_value
4343
4444 def remove (self ,node ) -> None :
45- pass
45+ node_to_remove = node
46+ current_head = self .head
47+ current_tail = self .tail
48+ if current_head == current_tail :
49+ #linkedlist has only one node
50+ self .head = None
51+ self .tail = None
52+ elif node_to_remove .next is None :
53+ #Node is the last node(tail)
54+ self .tail = node_to_remove .previous
55+ self .tail .next = None
56+ elif node_to_remove .previous is None :
57+ #Node is the first node(head)
58+ self .head = node_to_remove .next
59+ self .head .previous = None
60+ else :
61+ #Node is in the middle of list
62+ previous_node = node_to_remove .previous
63+ next_node = node_to_remove .next
64+ previous_node .next = next_node
65+ next_node .previous = previous_node
66+
67+ node_to_remove .next = None
68+ node_to_remove .previous = None
4669
You can’t perform that action at this time.
0 commit comments