使用二项队列来完成insert操作,不要调用merge

来源:互联网 发布:ubuntu下安装sqlyog 编辑:程序博客网 时间:2024/06/06 04:35

《数据结构与算法分析——c语言描述》 练习6.31 答案


void insert(ElementType X, BinQueue h) {BinTree t1;BinTree carry = malloc(sizeof(struct BinNode));if (carry == NULL)Error("EMPTY MEOERY");carry->element = X;carry->leftChild = carry->nextSibling = NULL;int carrt_tag;if (h->currentSize + 1 > CAPACITY)Error("TOO MUCH ELEM");h->currentSize += 1;int i = 0;while (carry != NULL) {t1 = h->theTrees[i];if (carry)carrt_tag = 1;elsecarrt_tag = 0;switch (!!t1 + 2 * !!carrt_tag) {case 0://t1,t2,carry空break;case 1://t1非空break;case 2://carry非空h->theTrees[i] = carry;carry = NULL;break;case 3://t1,carry非空carry = combineTrees(t1, carry);h->theTrees[i] = NULL;break;default:Error("error");break;}i++;}}


0 0
原创粉丝点击