Skip to content

Instantly share code, notes, and snippets.

@bansalayush
Created February 1, 2019 18:56
Show Gist options
  • Save bansalayush/54228a2357b4383b67aa28bdd75db73f to your computer and use it in GitHub Desktop.
Save bansalayush/54228a2357b4383b67aa28bdd75db73f to your computer and use it in GitHub Desktop.
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