示例#1
0
void makeheap(int s[], int n){
    int i=(n-1)/2;
    if(i>=0){
        for(;i!=0;i--){
            fixdown(s,i,n); 
        }
    }
}
示例#2
0
item_t pq_delmax(T t)
{
    /* remenber to change the a[1] instead of a[0],
     * because the the first element is inserted in position 1
     * instead of position 0*/
    swap(&t->content[1], t->content + t->size);
    fixdown(t->content, 1, t->size - 1);
    return t->content[t->size--];
}
示例#3
0
void vheapsort(int s[], int n)
{
    int i=n-1;
    int temp;
    makeheap(s, n);
    for(;i>=1;i++){
        temp=s[i];
        s[i]=s[0];
        s[0]=s[i];
        fixdown(s,--n,0);
    }
}