#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Node{
char left;
char right;
};
vector<Node> tree(26);
void Preorder(char current){
if(current=='.') return;
cout << current;
Preorder(tree[current-'A'].left);
Preorder(tree[current-'A'].right);
}
void Inorder(char current){
if(current=='.') return;
Inorder(tree[current-'A'].left);
cout << current;
Inorder(tree[current-'A'].right);
}
void Postorder(char current){
if(current=='.') return;
Postorder(tree[current-'A'].left);
Postorder(tree[current-'A'].right);
cout << current;
}
int main(){
int N;
cin >> N;
for(int i=0; i<N; i++){
char root, left, right;
cin >> root >> left >> right;
tree[root-'A'].left = left;
tree[root-'A'].right = right;
}
Preorder('A');
cout << endl;
Inorder('A');
cout << endl;
Postorder('A');
cout << endl;
return 0;
}
[백준(BOJ)] 2011번: 암호 코드(C++) (0) | 2025.01.04 |
---|---|
[백준(BOJ)] 11725: 트리의 부모 찾기(C++) (0) | 2025.01.03 |
[BOJ] 14501: 퇴사 (C++) (0) | 2024.03.24 |
[BOJ] 7576: 토마토 (C++) (1) | 2024.03.05 |
[Softeer] [HSAT 7회 정기 코딩 인증평가 기출] 순서대로 방문하기 (C++) (0) | 2024.02.25 |