From dea262bc6d16742b649fd7427c445ff121021d42 Mon Sep 17 00:00:00 2001 From: ParkSangWoo <162937325+AH100-1@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:57:13 +0900 Subject: [PATCH 1/4] Update main.py --- main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 5a3e755..d6ec0bd 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,14 @@ 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 cd126c1c762499b497130b730a44508fe75ed817 Mon Sep 17 00:00:00 2001 From: ParkSangWoo <162937325+AH100-1@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:27:42 +0900 Subject: [PATCH 2/4] 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 6994ec7..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) - priority, 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 20aad423a1ee5377cc5d03641997d47d69f580a9 Mon Sep 17 00:00:00 2001 From: ParkSangWoo <162937325+AH100-1@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:29:16 +0900 Subject: [PATCH 3/4] Rename test.py to test_1.py --- test.py => test_1.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test.py => test_1.py (100%) diff --git a/test.py b/test_1.py similarity index 100% rename from test.py rename to test_1.py From 71d4da20648049b7ac5ca7209a724443591fe0e6 Mon Sep 17 00:00:00 2001 From: ParkSangWoo <162937325+AH100-1@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:30:10 +0900 Subject: [PATCH 4/4] 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: