18____ binary tree mirror

Subject description:

Operation of a given binary tree, the binary tree is converted into a source image.

Mirroring definition of binary tree: binary source 
    	    8 
    	   / \ 
    	  610 
    	 / \ / \ 
    	57911 
    	mirror binary 
    	    8 
    	   / \ 
    	  106 
    	 / \ / \ 
    	11975


/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {
    public void Mirror(TreeNode root) {
        TreeNode temp=null;
        
        if(root!=null){  //交换左右子树
            temp=root.left;
            root.left=root.right;
            root.right=temp;
            
            if(root.left!=null ) {    // the left subtree is not empty, the left subtree exchange recursive 
                Mirror (root.left); 
            } 
            
            IF ! (root.right = null ) {   // when the right subtree is not empty, recursive exchange right subtree 
                Mirror (root.right); 
            } 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/xbfchder/p/11460962.html