Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
creating mirror of a tree
Given a Binary Tree, convert it into its mirror.
1 1
/ \ / \
3 2 ====> . 2 . 3
/ \ / \
5 4 4 5
traverse(node){
if(node == null){
return;
}
traverse(node -> left);
traverse(node -> right);
if(node->left!=null && node->right!=null){
nodeLeft = node->left;
node->left = node->right;
node->right = nodeLeft;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.