6.43③ 编写递归算法,将二叉树中所有结点的
左、右子树相互交换。
要求实现下列函数:
void Exchange(BiTree &bt);
/* Exchange the left and right leaves of */
/* bitree whose root node is bt */
二叉链表类型定义:
typedef struct BiTNode {
TElemType data;
BiTNode *lchild, *rchild;
左、右子树相互交换。
要求实现下列函数:
void Exchange(BiTree &bt);
/* Exchange the left and right leaves of */
/* bitree whose root node is bt */
二叉链表类型定义:
typedef struct BiTNode {
TElemType data;
BiTNode *lchild, *rchild;
} BiTNode, *BiTree;
********************************************************************
void Exchange(BiTree &bt)
/* Exchange the left and right leaves of */
/* bitree whose root node is bt */
{
if(bt)
{
BiTree t;
t=bt->lchild;
bt->lchild=bt->rchild;
bt->rchild=t;
Exchange(bt->lchild);
Exchange(bt->rchild);
}
}