二项队列添加元素

二项队列添加元素

from my csdn blog
二项队列,添加一个元素到队列中,不可用使用二项树合并函数。

//insert x into the binomial queue
BinQueue Insert(int x, BinQueue H){

    int i;
    BinTree Carry;

    if(H->CurrentSize+1 > Capacity){

        printf("no space for %d", x);
        return H;
    }                               //check the capacity

    H->CurrentSize++;   //inc the size of H

    Carry = createBinTree();
    Carry->element = x;
    Carry->leftChild = Carry->nextSibling = NULL;   // initialize the carry

    i = 0;
    while(H->TheTrees[i]){

        Carry = CombineTrees(Carry, H->TheTrees[i]);    //calculate the carry for high bit
        H->TheTrees[i++] = NULL;        //clean the TheTrees[i]
    }

    H->TheTrees[i] = Carry; //find the nonexistent position to place the carry

    return H;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容