-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1991.cpp
More file actions
60 lines (54 loc) · 812 Bytes
/
1991.cpp
File metadata and controls
60 lines (54 loc) · 812 Bytes
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
#include <iostream>
using namespace std;
typedef struct Tree {
char left;
char right;
}Tree;
char T[27][2];
void preorder(char root) {
if (root == '.') {
return;
}
else {
cout << root;
preorder(T[root - 'A'][0]);
preorder(T[root - 'A'][1]);
}
}
void inorder(char root) {
if (root == '.') {
return;
}
else {
inorder(T[root - 'A'][0]);
cout << root;
inorder(T[root - 'A'][1]);
}
}
void postorder(char root) {
if (root == '.') {
return;
}
else {
postorder(T[root - 'A'][0]);
postorder(T[root - 'A'][1]);
cout << root;
}
}
int main() {
int n, i;
char a, b, c;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a >> b >> c;
T[a - 'A'][0] = b;
T[a - 'A'][1] = c;
}
preorder('A');
cout << '\n';
inorder('A');
cout << '\n';
postorder('A');
cout << '\n';
return 0;
}