剣指offer(C++)--二叉樹の鏡像

873 ワード

タイトル
        ,            。

        :     
    	    8
    	   /  \
    	  6   10
    	 / \  / \
    	5  7 9 11
    	     
    	    8
    	   /  \
    	  10   6
    	 / \  / \
    	11 9 7  5
/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
    void Mirror(TreeNode *pRoot) {
         if(!pRoot) return ;
         if(!pRoot->left && !pRoot->right) return;
         TreeNode * pTmp = pRoot->left;
         pRoot->left = pRoot->right;
         pRoot->right = pTmp;
         if(pRoot->left)
         {
             Mirror(pRoot->left);
         }
         if(pRoot->right)
         {
             Mirror(pRoot->right);
         }
    }
};