-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13_boj_1991.cpp
63 lines (52 loc) · 949 Bytes
/
13_boj_1991.cpp
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
#include <cstdio>
#include <iostream>
#define MAX 27
using namespace std;
typedef struct Node{
char data;
char left;
char right;
}node;
node arr[MAX];
int n;
char a,b,c;
void preorder(char c) {
if (c=='.') {
return;
}
printf("%c", c);
preorder(arr[c-'A'].left);
preorder(arr[c-'A'].right);
}
void inorder(char c) {
if (c=='.') {
return;
}
inorder(arr[c-'A'].left);
printf("%c", c);
inorder(arr[c-'A'].right);
}
void postorder(char c) {
if (c=='.') {
return;
}
postorder(arr[c-'A'].left);
postorder(arr[c-'A'].right);
printf("%c", c);
}
int main() {
scanf("%d", &n);
for (int i=0; i<n; i++) {
scanf(" %c %c %c", &a, &b, &c);
arr[a-'A'].data=a;
arr[a-'A'].left=b;
arr[a-'A'].right=c;
}
preorder('A');
puts("");
inorder('A');
puts("");
postorder('A');
puts("");
return 0;
}