Created
December 10, 2019 21:58
-
-
Save rawsh/59a35736eedc1280bd51a77306c7fcc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void reheapDown(int i) { | |
int left = i*2 +1; | |
int right = i*2 +2; | |
if (right < size) { | |
int largerChild; | |
if (heap[left] >= heap[right]) { | |
largerChild = left; | |
} else { | |
largerChild = right; | |
} | |
T parent = heap[i]; | |
heap[i] = heap[largerChild]; | |
heap[largerChild] = parent; | |
reheapDown(largerChild); | |
} else if (left < size) { | |
T parent = heap[i]; | |
heap[i] = heap[left]; | |
heap[left] = parent; | |
reheapDown(left); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment