-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[BOJ] 1991번.cpp
76 lines (62 loc) · 1018 Bytes
/
[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
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Problem: 1991
* Solver: Jinwon
* Reference:
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
void preorder(char temp);
void inorder(char temp);
void postorder(char temp);
map<char, pair<char, char>> node;
int N;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int i;
char parent, leftChild, rightChild;
cin >> N;
for (i = 0; i < N; i++)
{
cin >> parent >> leftChild >> rightChild;
node[parent] = { leftChild, rightChild };
}
preorder('A');
cout << "\n";
inorder('A');
cout << "\n";
postorder('A');
return 0;
}
void preorder(char temp)
{
if (temp != '.')
{
cout << temp;
preorder(node[temp].first);
preorder(node[temp].second);
}
}
void inorder(char temp)
{
if (temp != '.')
{
inorder(node[temp].first);
cout << temp;
inorder(node[temp].second);
}
}
void postorder(char temp)
{
if (temp != '.')
{
postorder(node[temp].first);
postorder(node[temp].second);
cout << temp;
}
}