二叉树的镜像

来源:互联网 发布:淘宝怎么发链接到微信 编辑:程序博客网 时间:2024/05/17 08:27

题目描述
二叉树的镜像定义:源二叉树
8
/ \
6 10
/ \ / \
5 7 9 11
镜像二叉树
8
/ \
10 6
/ \ / \
11 9 7 5
分析
用另一种说法描述该题目就是递归交换每个节点的左右子树。
C++代码如下:

void Mirror(TreeNode *pRoot){    if(!pRoot) return;    TreeNode *tmp;    tmp = pRoot->left;    pRoot->left = pRoot->right;    pRoot->right = tmp;    Mirror(pRoot->left);    Mirror(pRoot->right)}
原创粉丝点击