Esempio n. 1
0
float get_first_value(heap_t *h)
{
    assert(h->curr_max > 0);
    float result = h->head[0];
    swap(h->head, 0, h->curr_max - 1);
    h->curr_max--;
    downward(h);
    return result;
}
Esempio n. 2
0
 void downward(int cur){
     int left = LCHILD(cur);
     int right = RCHILD(cur);
     if (left < size){
         int min = left;
         if (right < size && arr[right] < arr[left]) min = right;
         if (arr[min] < arr[cur]){
             swap(min, cur);
             downward(min);
         }
     }
 }
Esempio n. 3
0
 long long pop(){
     long long weight = arr[0];
     arr[0] = arr[--size];
     downward(0);
     return weight;
 }