From 39086dc8ca7d71040976006177396a6993ac2810 Mon Sep 17 00:00:00 2001 From: Praful Katare <47990928+Kpraful@users.noreply.github.com> Date: Sun, 8 Oct 2023 01:32:49 +0530 Subject: [PATCH] Fixes bug in PriorityQueue Algorithm; Fixes syntax in code for array. --- graphs/dijkstra_algorithm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graphs/dijkstra_algorithm.py b/graphs/dijkstra_algorithm.py index 452138fe9..89d8b341c 100644 --- a/graphs/dijkstra_algorithm.py +++ b/graphs/dijkstra_algorithm.py @@ -21,11 +21,11 @@ class PriorityQueue: def min_heapify(self, idx): lc = self.left(idx) rc = self.right(idx) - if lc < self.cur_size and self.array(lc)[0] < self.array(idx)[0]: + if lc < self.cur_size and self.array[lc][0] < self.array[idx][0]: smallest = lc else: smallest = idx - if rc < self.cur_size and self.array(rc)[0] < self.array(smallest)[0]: + if rc < self.cur_size and self.array[rc][0] < self.array[smallest][0]: smallest = rc if smallest != idx: self.swap(idx, smallest) @@ -43,7 +43,7 @@ class PriorityQueue: min_node = self.array[0][1] self.array[0] = self.array[self.cur_size - 1] self.cur_size -= 1 - self.min_heapify(1) + self.min_heapify(0) del self.pos[min_node] return min_node