Created
February 1, 2019 18:56
-
-
Save bansalayush/54228a2357b4383b67aa28bdd75db73f to your computer and use it in GitHub Desktop.
creating mirror of a tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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