-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMirror_of_Binary_Tree.cpp
More file actions
58 lines (47 loc) · 1.02 KB
/
Copy pathMirror_of_Binary_Tree.cpp
File metadata and controls
58 lines (47 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
struct Node
{
int val;
Node* left;
Node* right;
}root;
Node* createNode(int val)
{
Node* newNode = new Node;
newNode->val = val;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
void inorder(Node* root)
{
if(root == NULL)
return;
inorder(root->left);
cout<<root->val<<" ";
inorder(root->right);
}
void mirror(Node* root , Node** mirrortree)
{
if(root == NULL)
return;
*mirrortree = createNode(root->val);
mirror(root->left , &((*mirrortree)->right));
mirror(root->right , &((*mirrortree)->left));
}
int main()
{
Node* tree = createNode(5);
tree->left = createNode(3);
tree->right = createNode(6);
tree->left->left = createNode(2);
tree->left->right = createNode(4);
cout<<"Inorder of original tree: ";
inorder(tree);
Node* mirrortree = NULL;
mirror(tree , &mirrortree);
cout<<"\nInorder of mirror tree: ";
inorder(mirrortree);
return 0;
}