1.递归法
void Mirror(TreeNode *pRoot) {if(!pRoot || (pRoot->left == nullptr && pRoot->right == nullptr))return;//或者只是if(!pRoot)TreeNode* temp = pRoot->left;pRoot->left = pRoot->right;pRoot->right = temp;if(pRoot->left)Mirror(pRoot->left);if(pRoot->right)Mirror(pRoot->right);}
2.非递归
void Mirror(TreeNode *pRoot) {
if(!pRoot)return;
queue<TreeNode*> q;
q.push(pRoot);
TreeNode *tr, *temp;
while(!q.empty()){
tr = q.front();
if(tr->left || tr->right){
temp = tr->left;
tr->left = tr->right;
tr->right = temp;
if(tr->left)q.push(tr->left);
if(tr->right)q.push(tr->right);
}
q.pop();
}
}
