File tree Expand file tree Collapse file tree
Sprint-2/implement_linked_list Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class Node :
22 """
3- A node in a double linked list.
3+ A node in a doubly linked list.
44
55 Each node supports a data, previous, and next
66 - data: the value
77 - previous: pointer to the previous node
88 - next: pointer to the next node
99 """
10+ _slots_ = ("data" , "previous" , "next" )
1011
1112 def __init__ (self , data ):
1213 self .data = data
@@ -69,19 +70,10 @@ def pop_tail(self):
6970 raise ValueError ("List is empty." )
7071
7172 # store value before removing node
72- value = self .tail .data
73+ node = self .tail
74+ value = node .data
7375
74- if self .head == self .tail :
75- # Only one element in the list
76- self .head = None
77- self .tail = None
78-
79- else :
80- # Move tail pointer backwards
81- self .tail = self .tail .previous
82-
83- # Disconnect old tail node
84- self .tail .next = None
76+ self .remove (node )
8577
8678 return value
8779
You can’t perform that action at this time.
0 commit comments