From c93934748fd41ee1a9c140a4a15525d0439fc5d0 Mon Sep 17 00:00:00 2001 From: awj1052 Date: Mon, 17 Mar 2025 16:51:56 +0900 Subject: [PATCH 1/3] fix: typo --- main.py | 18 ++++++++---------- priority_queue.py | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 5a3e755..940e33a 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() 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 a900c3495033001d5a475143f9262edbc3ba1b1e Mon Sep 17 00:00:00 2001 From: awj1052 Date: Mon, 17 Mar 2025 17:02:24 +0900 Subject: [PATCH 2/3] fix: pq logic --- 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: From 5b835e07152ae0b1f7b4f028c1f81475a0e7f5c3 Mon Sep 17 00:00:00 2001 From: awj1052 Date: Mon, 17 Mar 2025 17:04:23 +0900 Subject: [PATCH 3/3] fix: run test cmd --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5420c17..9f5aafd 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -41,4 +41,4 @@ jobs: pylint *.py - name: Test with pytest run: | - pytest + python test.py