diff --git a/dohyeondol1/README.md b/dohyeondol1/README.md index e5e0561..586986f 100644 --- a/dohyeondol1/README.md +++ b/dohyeondol1/README.md @@ -8,4 +8,5 @@ | 4차시 | 2025.03.28 | BFS | [점프왕 쩰리 (Large)](https://www.acmicpc.net/problem/16174)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/15| | 5차시 | 2025.04.02 | DFS & BFS | [DFS와 BFS](https://www.acmicpc.net/problem/1260)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/18| | 6차시 | 2025.04.05 | DP | [평범한 배낭](https://www.acmicpc.net/problem/12865)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/22| + | 7차시 | 2025.04.08 | 트리 | [트리 순회](https://www.acmicpc.net/problem/1991)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/26| --- \ No newline at end of file diff --git "a/dohyeondol1/\355\212\270\353\246\254/7-dohyeondol1.cpp" "b/dohyeondol1/\355\212\270\353\246\254/7-dohyeondol1.cpp" new file mode 100644 index 0000000..61f975d --- /dev/null +++ "b/dohyeondol1/\355\212\270\353\246\254/7-dohyeondol1.cpp" @@ -0,0 +1,50 @@ +#include +using namespace std; +pair node[26]; +int N; + +//전위순회 +void preorder(char current){ + if(current == '.') + return; + + cout << current; + preorder(node[current-'A'].first); + preorder(node[current-'A'].second); +} + +//중위순회 +void inorder(char current){ + if(current == '.') + return; + + inorder(node[current-'A'].first); + cout << current; + inorder(node[current-'A'].second); +} + +//후위순회 +void postorder(char current){ + if(current == '.') + return; + + postorder(node[current-'A'].first); + postorder(node[current-'A'].second); + cout << current; +} + +int main(){ + cin >> N; + for(int i = 0; i < N; i++){ + char parent, left, right; + cin >> parent >> left >> right; + node[parent-'A'].first = left; + node[parent-'A'].second = right; + } + + preorder('A'); + cout << "\n"; + inorder('A'); + cout << "\n"; + postorder('A'); +} \ No newline at end of file