diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index d868578..57c0ce8 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -19,5 +19,5 @@ | 15차시 | 2024.04.09 | 구현 | [BOJ 14719](https://www.acmicpc.net/problem/14719) | [BOJ 14719 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/48) | | 16차시 | 2024.04.11 | 애드 혹 | [BOJ 15927](https://www.acmicpc.net/problem/15927) | [BOJ 15927 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/51) | | 17차시 | 2024.04.15 | DP | [BOJ 11726](https://www.acmicpc.net/problem/11726) | [BOJ 11726 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/53) | - +| 18차시 | 2024.04.15 | 트리 | [BOJ 5639](https://www.acmicpc.net/problem/5639) | [BOJ 5639 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/53) | --- \ No newline at end of file diff --git "a/YIM2UL2ET/\355\212\270\353\246\254/18\354\260\250\354\213\234 - BOJ 5639.cpp" "b/YIM2UL2ET/\355\212\270\353\246\254/18\354\260\250\354\213\234 - BOJ 5639.cpp" new file mode 100644 index 0000000..ed5a18c --- /dev/null +++ "b/YIM2UL2ET/\355\212\270\353\246\254/18\354\260\250\354\213\234 - BOJ 5639.cpp" @@ -0,0 +1,34 @@ +#include +using namespace std; + +struct node { + int value = -1; + node* right = NULL; + node* left = NULL; +}; + +void input(node &nd, int n) { + if (nd.value == -1) nd.value = n; + else if (nd.value > n) { + if (nd.left == NULL) nd.left = new node; + input(*nd.left, n); + } + else { + if (nd.right == NULL) nd.right = new node; + input(*nd.right, n); + } +} + +void output(node &nd) { + if (nd.left != NULL) output(*nd.left); + if (nd.right != NULL) output(*nd.right); + cout << nd.value << '\n'; +} + +int main(void) { + int n; + node root; + while (cin >> n) input(root, n); + output(root); + return 0; +} \ No newline at end of file