操做給定的二叉樹,將其變換爲源二叉樹的鏡像。

public class Solution {code

public void Mirror(TreeNode root) {
     //節點爲空返回
    if(root==null)
	
        return;
		
    TreeNode temp;
	//交換左右節點
    temp=root.left;
	
    root.left=root.right;
	
    root.right=temp;
	//若是左子樹還有子節點,在來一次
    Mirror(root.left);
	//若是右子樹還有子節點,在來一次
    Mirror(root.right);
	
        
}

}io

相關文章
相關標籤/搜索