From dd7584f6575568ef8236148f1d426b8bc345bad1 Mon Sep 17 00:00:00 2001 From: haaaanung <129250257+haaaanung@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:50:51 +0900 Subject: [PATCH 1/7] Update main.py --- main.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 5a3e755..cfac9ef 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,12 @@ from priority_queue import PriorityQueue def main(): - pq = PriorityQueue() - - pq.push("Task 1", 3) - pq.push("Task 2", 1) - pq.push("Task 3", 2) - - print(pq.pop()) - print(pq.pop()) - print(pq.pop()) + pq = PriorityQueue() + pq.push("Task 1", 3) + pq.push("Task 2", 1) + pq.push("Task 3", 2) + print(pq.pop()) + print(pq.pop()) + print(pq.pop()) if __name__ == "__main__": - main() \ No newline at end of file + main() From 65c022efb01a23a8ba7a6890808bfaaf009999e4 Mon Sep 17 00:00:00 2001 From: haaaanung <129250257+haaaanung@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:53:18 +0900 Subject: [PATCH 2/7] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index cfac9ef..940e33a 100644 --- a/main.py +++ b/main.py @@ -9,4 +9,4 @@ def main(): print(pq.pop()) if __name__ == "__main__": - main() + main() From d0263f490220ab6a559e783e0588ee9a985fb66e Mon Sep 17 00:00:00 2001 From: haaaanung <129250257+haaaanung@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:54:53 +0900 Subject: [PATCH 3/7] Update priority_queue.py --- priority_queue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priority_queue.py b/priority_queue.py index 6994ec7..0b17bc4 100644 --- a/priority_queue.py +++ b/priority_queue.py @@ -10,7 +10,7 @@ def push(self, item, priority): def pop(self): if len(self.heap) > 1: self._swap(0, len(self.heap) - 1) - priority, item = self.heap.pop() + item = self.heap.pop() self._sift_down(0) return item elif len(self.heap) == 1: From f9dd6bfd0ebff39f52591c37f18263855cefd561 Mon Sep 17 00:00:00 2001 From: haaaanung <129250257+haaaanung@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:00:08 +0900 Subject: [PATCH 4/7] Update priority_queue.py --- priority_queue.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/priority_queue.py b/priority_queue.py index 0b17bc4..9bc9135 100644 --- a/priority_queue.py +++ b/priority_queue.py @@ -10,11 +10,11 @@ def push(self, item, priority): def pop(self): if len(self.heap) > 1: self._swap(0, len(self.heap) - 1) - item = self.heap.pop() + _, item = self.heap.pop() self._sift_down(0) return item elif len(self.heap) == 1: - priority, item = self.heap.pop() + _, item = self.heap.pop() return item else: return None From 770ba87c36b378fd62cb5e7e0dff6e67397de93b Mon Sep 17 00:00:00 2001 From: haaaanung <129250257+haaaanung@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:12:03 +0900 Subject: [PATCH 5/7] Rename test.py to test_code.py --- test.py => test_code.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test.py => test_code.py (100%) diff --git a/test.py b/test_code.py similarity index 100% rename from test.py rename to test_code.py From 86612c5517580681918a1972681877ae3caace4a Mon Sep 17 00:00:00 2001 From: haaaanung <129250257+haaaanung@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:15:04 +0900 Subject: [PATCH 6/7] Rename test_code.py to test_.py --- test_code.py => test_.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_code.py => test_.py (100%) diff --git a/test_code.py b/test_.py similarity index 100% rename from test_code.py rename to test_.py From 6c91d2969c8f0941ff255c08b5fc4c9e4ed63114 Mon Sep 17 00:00:00 2001 From: haaaanung <129250257+haaaanung@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:21:14 +0900 Subject: [PATCH 7/7] Update priority_queue.py --- priority_queue.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/priority_queue.py b/priority_queue.py index 9bc9135..f54f6be 100644 --- a/priority_queue.py +++ b/priority_queue.py @@ -35,11 +35,11 @@ def _sift_down(self, index): smallest = index if left_child_index < len(self.heap) and \ - self.heap[left_child_index][0] > self.heap[smallest][0]: + self.heap[left_child_index][0] < self.heap[smallest][0]: smallest = left_child_index if right_child_index < len(self.heap) and \ - self.heap[right_child_index][0] > self.heap[smallest][0]: + self.heap[right_child_index][0] < self.heap[smallest][0]: smallest = right_child_index if smallest != index: