美文网首页
二项队列添加元素

二项队列添加元素

作者: Amrzs | 来源:发表于2014-06-14 12:18 被阅读70次

    二项队列添加元素

    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;
    }
    

    相关文章

      网友评论

          本文标题:二项队列添加元素

          本文链接:https://www.haomeiwen.com/subject/elqjtttx.html