-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1991.cpp
More file actions
49 lines (40 loc) · 710 Bytes
/
1991.cpp
File metadata and controls
49 lines (40 loc) · 710 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
#include "stdafx.h"
int a[30][2];
void preorder(int x) {
if (x == -1) return;
printf("%c", x + 'A');
preorder(a[x][0]);
preorder(a[x][1]);
}
void inorder(int x) {
if (x == -1) return;
inorder(a[x][0]);
printf("%c", x + 'A');
inorder(a[x][1]);
}
void postorder(int x) {
if (x == -1) return;
postorder(a[x][0]);
postorder(a[x][1]);
printf("%c", x + 'A');
}
int main() {
int n, k;
char x, y, z;
scanf("%d", &n);
while (n--) {
scanf(" %c %c %c", &x, &y, &z);
k = x - 'A';
if (y == '.') a[k][0] = -1;
else a[k][0] = y - 'A';
if(z == '.') a[k][1] = -1;
else a[k][1] = z - 'A';
}
preorder(0);
printf("\n");
inorder(0);
printf("\n");
postorder(0);
printf("\n");
return 0;
}