题目描述:
操作给定的二叉树,将其变换为源二叉树的镜像。
二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 7 5
题目分析:
先前序遍历这棵树的每个结点,如果遍历到的结点有子结点,就交换它的两个子节点,
当交换完所有的非叶子结点的左右子结点之后,就得到了树的镜像
代码:
function Mirror(root)
{
// write code here
if(root == null){
return null;
}
var tem = root.left;
root.left = root.right;
root.right = tem;
Mirror(root.right);
Mirror(root.left);
}