Skip to content

Instantly share code, notes, and snippets.

@rawsh
Created December 10, 2019 21:58
Show Gist options
  • Save rawsh/59a35736eedc1280bd51a77306c7fcc4 to your computer and use it in GitHub Desktop.
Save rawsh/59a35736eedc1280bd51a77306c7fcc4 to your computer and use it in GitHub Desktop.
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