//方案一:
public class Solution {
public void Mirror(TreeNode root) {
if(root==null)
return;
TreeNode temp=root.left;
root.left=root.right;
root.right=temp;
Mirror(root.left);
Mirror(root.right);
}
}
//方案二:
import java.util.*;
public class Solution {
public void Mirror(TreeNode root) {
if(root==null)
return;
Stack <TreeNode> stack = new Stack<TreeNode>();
stack.push(root);
while(!stack.isEmpty()){
TreeNode cur=stack.pop();
if(cur.left!=null||cur.right!=null){
TreeNode temp=cur.left;
cur.left=cur.right;
cur.right=temp;
}
if(cur.left!=null)
stack.push(cur.left);
if(cur.right!=null)
stack.push(cur.right);
}
}
}