File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ def append(self, value): # O(1)
4343 self .length += 1
4444
4545 def appendleft (self , value ):
46+ if self .maxsize is not None and len (self ) > self .maxsize :
47+ raise Exception ('LinkedList is Full' )
4648 headnode = self .root .next
4749 node = Node (value )
4850 self .root .next = node
@@ -100,6 +102,9 @@ def popleft(self): # O(1)
100102 self .root .next = headnode .next
101103 self .length -= 1
102104 value = headnode .value
105+
106+ if self .tailnode is headnode : # 勘误:增加单节点删除 tailnode 处理
107+ self .tailnode = None
103108 del headnode
104109 return value
105110
@@ -138,6 +143,12 @@ def test_linked_list():
138143 assert len (ll ) == 2
139144 assert list (ll ) == [1 , 3 ]
140145
146+ assert ll .popleft () == 1
147+ assert list (ll ) == [3 ]
148+ ll .popleft ()
149+ assert len (ll ) == 0
150+ assert ll .tailnode is None
151+
141152 ll .clear ()
142153 assert len (ll ) == 0
143154
You can’t perform that action at this time.
0 commit comments