二叉树的镜像

来源:互联网 发布:c 数据库编程 编辑:程序博客网 时间:2024/05/19 17:50

二叉树的镜像定义:源二叉树

        8       /  \      6   10     / \  / \    5  7 9 11    镜像二叉树        8       /  \      10   6     / \  / \    11 9 7  5

//递归
public TreeNode Mirror(TreeNode root)
{
// write code here
if (root == null)
{
return root;
}
else
{
TreeNode Temp = root.left;
root.left = root.right;
root.right = Temp;
Mirror(root.left);
Mirror(root.right);
return root;
}
}

0 0