(1)voidAA(BiTree*T){if(T){printf("%c",T->data);AA(T->lchild);AA(T->rchild);}}Writethefunctionofthealgorithmabove.(5.0分)
举一反三
- 1.编写递归算法,将二叉树中所有结点的左、右子树相互交换。 StatusExchangeBiTree(BiTree& T) { BiTree p; if(T){ p=T->lchild; T->lchild=T->rchild; T->rchild=p; ExchangeBiTree(T->lchild); } return OK; }
- 写递归算法,将二叉树中所有结点的左、右子树相互交换。 Status ExchangeBiTree(BiTree& T) { BiTreep; if(T){ p=T->lchild; T->lchild=T->rchild; T->rchild=p; ExchangeBiTree(T->lchild); __________ } returnOK; }
- 写出下面算法的功能。Bitree*function(Bitree*bt){Bitree*t,*t1,*t2;if(bt==NULL)t=NULL;else{t=(Bitree*)malloc(sizeof(Bitree));t->data=bt->data;t1=function(bt->left);t2=function(bt->right);t->left=t2;t->right=t1;}return(t);}
- 二叉排序树采用二叉链表存储,结点结构为:lchild|data|rchild,指针lchild和rchild分别指向结点的左右孩子结点。令T指向根结点,则求T的左子树上最大的结点算法的核心语句是( )。 A: if (T) { s=T->lchild;if (s) { while(s->rchild) s=s->rchild; }}return s; B: if (T) { s=T->rchild;if (s) { while(s->rchild) s=s->rchild; }}return s; C: if (T) { s=T->rchild;if (s) { while(s->lchild) s=s->lchild; }}return s; D: if (T) { s=T->lchild;if (s) { while(s->lchild) s=s->lchild; }}return s;
- 1.编写递归算法,将二叉树中所有结点的左、右子树相互交换。StatusExchangeBiTree(BiTree&T){BiTreep;if(T){p=T->lchild;T->lchild=T->rchild;T->rchild=p;ExchangeBiTree(T->lchild);}returnOK;}