heap.c
void minHeapify(struct MinHeap *minHeap, int idx) {
    int smallest, left, right;
    smallest = idx;
    left = 2 * idx + 1;
    right = 2 * idx + 2;

    if (left < minHeap->size && minHeap->array[left]->dist < minHeap->array[smallest]->dist)
        smallest = left;

    if (right < minHeap->size && minHeap->array[right]->dist < minHeap->array[smallest]->dist)
        smallest = right;

    if (smallest != idx)
    {
        struct MinHeapNode *smallestNode = minHeap->array[smallest];
        struct MinHeapNode *idxNode = minHeap->array[idx];

        minHeap->pos[smallestNode->v] = idx;
        minHeap->pos[idxNode->v] = smallest;
        swapMinHeapNode(&minHeap->array[smallest], &minHeap->array[idx]);

        minHeapify(minHeap, smallest);
    }
}
// A standard function to heapify at given idx
// This function also updates position of nodes when they are swapped.
A standard function to heapify at given idx
This function also updates position of nodes when they are swapped.
A standard function to heapify at given idx This function also updates position of nodes when they are swapped .
void minHeapify(struct MinHeap *minHeap, int idx) {
    int smallest, left, right;
    smallest = idx;
    left = 2 * idx + 1;
    right = 2 * idx + 2;
    if (left < minHeap->size && minHeap->array[left]->dist < minHeap->array[smallest]->dist)
        smallest = left;
    if (right < minHeap->size && minHeap->array[right]->dist < minHeap->array[smallest]->dist)
        smallest = right;
    if (smallest != idx)
    {
        struct MinHeapNode *smallestNode = minHeap->array[smallest];
        struct MinHeapNode *idxNode = minHeap->array[idx];
        minHeap->pos[smallestNode->v] = idx;
        minHeap->pos[idxNode->v] = smallest;
        swapMinHeapNode(&minHeap->array[smallest], &minHeap->array[idx]);
        minHeapify(minHeap, smallest);
    }
}
void minHeapify ( struct MinHeap * minHeap , int idx ) { int smallest , left , right ; smallest = idx ; left = 2 * idx + 1 ; right = 2 * idx + 2 ; if ( left < minHeap -> size && minHeap -> array [ left ] -> dist < minHeap -> array [ smallest ] -> dist ) smallest = left ; if ( right < minHeap -> size && minHeap -> array [ right ] -> dist < minHeap -> array [ smallest ] -> dist ) smallest = right ; if ( smallest != idx ) { struct MinHeapNode * smallestNode = minHeap -> array [ smallest ] ; struct MinHeapNode * idxNode = minHeap -> array [ idx ] ; minHeap -> pos [ smallestNode -> v ] = idx ; minHeap -> pos [ idxNode -> v ] = smallest ; swapMinHeapNode ( & minHeap -> array [ smallest ] , & minHeap -> array [ idx ] ) ; minHeapify ( minHeap , smallest ) ; } }
A standard function to heapify at given idx
This function also updates position of nodes when they are swapped.
A standard function to heapify at given idx This function also updates position of nodes when they are swapped .