Remove Min
int remove_min(Bheap *H)
{
    int tmp, min, ans;
    if (H->cnt == 0) {
        printf("Binary heap is empty\n");
        return 0;
    }
    ans = H->array[1];
    H->array[1] = H->array[H->cnt--];
 
    tmp = 1;
    while (1) {
        if (2*tmp + 1 <= H->cnt)
            min = (H->array[2*tmp + 1] < H->array[2*tmp]) ? 2*tmp + 1 : 2*tmp;
        else if (2*tmp <= H->cnt)
            min = 2*tmp;
        else
            break;
 
        if (H->array[tmp] > H->array[min]) {
            swap(H, tmp, min);
            tmp = min;
        }
        else
            break;
    }
 
    return ans;
}
 
int min(Bheap *H)
{
    if (H->cnt == 0) {
        printf("Binary heap is empty\n");
        return 0;
    }
    else
        return H->array[1];
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License