镜像是指将节点的左右节点交换,对左右子树也施加相同的操作
void Mirror(TreeNode* root)
{
if(root == NULL)return;
if(root->left == NULL && root->right == NULL)return;
TreeNode* temp = root->left;
root->left = root->right;
root->right = temp;
if(root->left) Mirror(root->left);
if(root->right) Mirror(root->right);
}
网友评论