From 6df175bd7d078626992c43b37c7f26c9e33fc85d Mon Sep 17 00:00:00 2001 From: youjin <146078042+jeongyoujin0203@users.noreply.github.com> Date: Sun, 23 Mar 2025 21:30:42 +0900 Subject: [PATCH 1/6] Update main.py --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 5a3e755..c4da2c8 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,15 @@ 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()) if __name__ == "__main__": - main() \ No newline at end of file + main() From 4a28ef78ff4c4fd42a6fae4f600e60f99001e85e Mon Sep 17 00:00:00 2001 From: youjin <146078042+jeongyoujin0203@users.noreply.github.com> Date: Sun, 23 Mar 2025 21:31:13 +0900 Subject: [PATCH 2/6] 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..6da96d9 100644 --- a/priority_queue.py +++ b/priority_queue.py @@ -3,7 +3,7 @@ def __init__(self): self.heap = [] def push(self, item, priority): - entry = (priority, item) + entry = (_priority, item) self.heap.append(entry) self._sift_up(len(self.heap) - 1) From 6b4e3f97685c0f5de31ea7cddb6f964709d4103e Mon Sep 17 00:00:00 2001 From: youjin <146078042+jeongyoujin0203@users.noreply.github.com> Date: Sun, 23 Mar 2025 21:33:48 +0900 Subject: [PATCH 3/6] Update main.py --- main.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index c4da2c8..dd152e5 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,13 @@ 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() + main() From 97310ade2a7b63e57a97c8c0a5d5909727bc0186 Mon Sep 17 00:00:00 2001 From: youjin <146078042+jeongyoujin0203@users.noreply.github.com> Date: Sun, 23 Mar 2025 21:35:06 +0900 Subject: [PATCH 4/6] 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 6da96d9..6994ec7 100644 --- a/priority_queue.py +++ b/priority_queue.py @@ -3,7 +3,7 @@ def __init__(self): self.heap = [] def push(self, item, priority): - entry = (_priority, item) + entry = (priority, item) self.heap.append(entry) self._sift_up(len(self.heap) - 1) From 0be45f0070e22080a6f32ab4896995f31dd7d89f Mon Sep 17 00:00:00 2001 From: youjin <146078042+jeongyoujin0203@users.noreply.github.com> Date: Sun, 23 Mar 2025 21:44:35 +0900 Subject: [PATCH 5/6] Update priority_queue.py --- priority_queue.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/priority_queue.py b/priority_queue.py index 6994ec7..f54f6be 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 @@ -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: From 4a7297af2c30a3a07604b180d486b5714dad981b Mon Sep 17 00:00:00 2001 From: youjin <146078042+jeongyoujin0203@users.noreply.github.com> Date: Sun, 23 Mar 2025 21:46:24 +0900 Subject: [PATCH 6/6] Rename test.py to test_.py --- test.py => test_.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test.py => test_.py (100%) diff --git a/test.py b/test_.py similarity index 100% rename from test.py rename to test_.py