剑指OFFER 二叉树的镜像
剑指OFFER 二叉树的镜像
深搜的变形
/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
queue<TreeNode*> que;
void Mirror(TreeNode* root) {
if(root == NULL)return;
que.push(root);
while(que.size()!=0)
{
TreeNode* node = que.front();
que.pop();
TreeNode* tmp = node->left;
node->left = node->right;
node->right = tmp;
if(node->left != NULL)
{
que.push(node->left);
}
if(node->right != NULL)
{
que.push(node->right);
}
}
}
};