let rec bubbledown heap idx =
try
if heap.compare (get heap idx) (get heap (left_child idx)) > 0
then (swap heap idx (left_child idx);
bubbledown heap (left_child idx))
else
if heap.compare (get heap idx) (get heap (right_child idx)) > 0
then (swap heap idx (right_child idx);
bubbledown heap (right_child idx))
else ()
with
| _ -> ()