Hi,
I'm trying to extract the minimum from a binary heap but it's not working. Here's my BubbleDown code:
void heapBubbleDown(Heap * const heap, int idx) {
int min;
while(RIGHT(idx) < heap->count) {
min = LEFT(idx);
if(RIGHT(idx) < heap->count) {
if(heap->items[LEFT(idx)] > heap->items[RIGHT(idx)]) {
min = RIGHT(idx);
}
}
heapSwapValue(&(heap->items[idx]), &(heap->items[min]));
idx = min;
}
}
It looks like it only swaps a few numbers but not all of them, I can't understand why. I tried to recode it differently and many times already...
What am I doing wrong?