《数据结构与算法分析——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;
else
carrt_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++;
}
}