From cd98166da5c0cc84fd1cd8bbf1b17568760d856c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=8A=B9=ED=98=B8?= <132066506+YIM2UL2ET@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:23:39 +0900 Subject: [PATCH] =?UTF-8?q?18=EC=B0=A8=EC=8B=9C=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YIM2UL2ET/README.md | 2 +- ...18\354\260\250\354\213\234 - BOJ 5639.cpp" | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 "YIM2UL2ET/\355\212\270\353\246\254/18\354\260\250\354\213\234 - BOJ 5639.cpp" 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