From 35286e30a6b17f41b1f86df986aa301521edfb54 Mon Sep 17 00:00:00 2001 From: MstrPikachu <31784486+MstrPikachu@users.noreply.github.com> Date: Sat, 22 Jan 2022 23:18:26 -0500 Subject: [PATCH] A1 P1 Q1 Fix bug in heuristic 3 Fix faulty while loop --- assignments/A1/a1_part1.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/assignments/A1/a1_part1.py b/assignments/A1/a1_part1.py index 2578853..7202a13 100644 --- a/assignments/A1/a1_part1.py +++ b/assignments/A1/a1_part1.py @@ -159,14 +159,15 @@ class CountLinkedList(LinkedList): return False if count > self._first.access_count: - node = _CountNode(item, self._first, count) - self._first = node # insert to front + self._first = _CountNode(item, self._first, count) # insert to front return True cur = self._first - while cur.next and cur.next.access_count < count: + while cur.next and cur.next.access_count >= count: cur = cur.next - cur.next = _CountNode(item, cur.next.next if cur.next else None, count) # insert node + + cur.next = _CountNode(item, cur.next, count) # insert node + print(count) return True def append(self, item: Any) -> None: