class Solution {
public:
    TreeNode* Mirror(TreeNode* pRoot) {
        if(!pRoot) return nullptr;
        //使用一个stack
        stack<TreeNode*> stackTreeNode;
        stackTreeNode.push(pRoot);

        while(!stackTreeNode.empty()){
            TreeNode* pNode=stackTreeNode.top();
            stackTreeNode.pop();

            TreeNode* pTmp=pNode->left;
            pNode->left=pNode->right;
            pNode->right=pTmp;

            if(pNode->left)
                stackTreeNode.push(pNode->left);
            if(pNode->right)
                stackTreeNode.push(pNode->right);       
        }
        return pRoot;
    }
};
class Solution {
public:
    TreeNode* Mirror(TreeNode* pRoot) {
        if(!pRoot) return nullptr;
        if(!pRoot->left && !pRoot->right) return pRoot; 

        TreeNode* pTmp=pRoot->left;
        pRoot->left=pRoot->right;
        pRoot->right=pTmp;

        if(pRoot->left) Mirror(pRoot->left);
        if(pRoot->right) Mirror(pRoot->right);

        return pRoot;
    }
};