A1 P1 Q1 Fix bug in heuristic 3

Fix faulty while loop and now returns true at the end
This commit is contained in:
MstrPikachu
2022-01-22 22:08:48 -05:00
parent 85d6e3ac3d
commit adb17b5743
2 changed files with 11 additions and 2 deletions
+3 -2
View File
@@ -164,9 +164,10 @@ class CountLinkedList(LinkedList):
return True
cur = self._first
while (not cur.next) or cur.next.access_count < count:
while cur.next and cur.next.access_count < count:
cur = cur.next
cur.next = _CountNode(item, cur.next.next, count) # insert node
cur.next = _CountNode(item, cur.next.next if cur.next else None, count) # insert node
return True
def append(self, item: Any) -> None:
"""Add the given item to the end of this linked list.