From 52800707eeca39d557d71e14a911a439f12dfd1c Mon Sep 17 00:00:00 2001 From: pjs <pjs@alum.mit.edu> Date: Fri, 4 Nov 2016 16:28:59 -0400 Subject: [PATCH] tweaks to priority queue implementation --- lib/priority_queue.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/priority_queue.rb b/lib/priority_queue.rb index 9f2272f..0d77512 100644 --- a/lib/priority_queue.rb +++ b/lib/priority_queue.rb @@ -22,7 +22,7 @@ class PriorityQueue min = @elements[1] # and make sure the tree is ordered again - bubble_down(1) + bubble_down(1) unless empty? min end @@ -62,7 +62,7 @@ class PriorityQueue child_index = (index * 2) # stop if we reach the bottom of the tree - if child_index > @elements.size - 1 + if child_index >= @elements.size @elements[index] = target return end -- GitLab