-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmirrorimage.cpp
More file actions
83 lines (68 loc) · 1.13 KB
/
mirrorimage.cpp
File metadata and controls
83 lines (68 loc) · 1.13 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<bits/stdc++.h>
using namespace std;
struct node{
int data;
node *left;
node *right;
};
struct node *new_node(int num)
{
node*temp = new node();
temp->left=NULL;
temp->right=NULL;
temp->data=num;
return temp;
};
void inorder(node*root)
{
if(root==NULL)
{
return;
}
inorder(root->left);
cout<<root->data<<" ";
inorder(root->right);
}
void getparent(node*root,int parent,node**temp)
{
if(root==NULL)
{
return;
}
if(root->data==parent)
{
(*temp)=root;
getparent(root->left,parent,temp);
getparent(root->right,parent,temp);
}
}
node *getnode(node*root,int parent,int child,char ch)
{
node*temp =NULL;
getparent(root,parent,&temp);
if(ch=='R')
{
temp->right=new_node(child);
}
else
{
temp->left=new_node(child);
}
return root;
}
int main()
{
node*root=NULL;
root = new_node(1);
int n,k;
cin>>n>>k;
for(int i=0;i<n-1;i++)
{
int a,b;
char ch;
cin>>a>>b>>ch;
root = getnode(root,a,b,ch);
}
inorder(root);
return 0;
}