//use recursion public static void mirrorHelp1(Node node){ if(node==null)return; swapChild(node); mirrorHelp1(node.getLeft()); mirrorHelp1(node.getRight()); } //use no recursion but stack public static void mirrorHelp2(Node node){ if(node==null)return; Stack<Node> stack=new Stack<Node>(); stack.add(node); while(!stack.isEmpty()){ node=stack.pop(); swapChild(node); if(node.getLeft()!=null){ stack.push(node.getLeft()); } if(node.getRight()!=null){ stack.push(node.getRight()); } } } public static void swapChild(Node node){ /*not like c/c++,you cannot do this: Node temp=left; left=right; right=temp; */ Node left=node.getLeft(); node.setLeft(node.getRight()); node.setRight(left); }