package jianzhiOffer; /** * 操做給定的二叉樹,將其變換爲源二叉樹的鏡像。 * @author user * 二叉樹的鏡像定義:源二叉樹 8 / \ 6 10 / \ / \ 5 7 9 11 鏡像二叉樹 8 / \ 10 6 / \ / \ 11 9 7 5 */ class TreeNode2 { int val = 0; TreeNode2 left = null; TreeNode2 right = null; public TreeNode2(int val) { this.val = val; } } public class ch18 { TreeNode2 tmp_node = null; public void Mirror(TreeNode2 root) { if(root == null) { return; } Mirror(root.left); Mirror(root.right); tmp_node = root.left; root.left = root.right; root.right = tmp_node; } }