📄 6.43.c
字号:
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;
} BiTNode, *BiTree;
void Exchange(BiTree &bt)
/* Exchange the left and right leaves of */
/* bitree whose root node is bt */
{
struct BiTNode *temp;
temp=bt->rchild;
bt->rchild=bt->lchild;
bt->lchild=temp;
if(bt->rchild) Exchange(bt->rchild);
if(bt->lchild) Exchange(bt->lchild);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -