E G
B H I
五、阅读理解(每小题5分,共20分。至少要写出思路)
答:此题答案不唯一,但若从已给定序列中挑选,则限制颇多。
(7) Q=P;
(11) P=L; (8) while(P->next!=Q)P=P->next; (10) P=Q; (4) S->next=P->next;
P->next=S;
2、答:这是找结点后继的程序。
共有3处错误。
注:当rtag=1时说明内装后继指针,可直接返回,第一句无错。
当rtag=0时说明内装右孩子指针,但孩子未必是后继,需要计算。中序遍历应当先左再根再右,所以应当找左子树直到叶子处。r=r->lchild; 直到LTag=1;
应改为:while(!r->Ltag)r=r->Lchild;
3. 写出下列程序段的输出结果(队列中的元素类型QElem Type为char)。
void main( ){
Queue Q; Init Queue (Q);
Char x=’e’; y=’c’;
EnQueue (Q,’h’); EnQueue (Q,’r’); EnQueue (Q, y);
DeQueue (Q,x); EnQueue (Q,x);
DeQueue (Q,x); EnQueue (Q,’a’);
while(!QueueEmpty(Q)){ DeQueue (Q,y);printf(y); };
Printf(x);
}