Suppose there is a tree:
1
/ \\
2 3
/ \\
4 5
Then the mirror image will
struct node *MirrorOfBinaryTree( struct node *root)
{ struct node *temp;
if(root)
{
MirrorOfBinaryTree(root->left);
MirrorOfBinaryTree(root->right);
/*swap the pointers in this node*/
temp=root->right;
root->right=root->left;;
root->left=temp;
}
return root;
}
Time complexity: O(n) Space complexity: O(n)