-
58. 이진트리 깊이우선탐색 (DFS: Depth First Search) [재귀 & 깊이/넓이 우선탐색(DFS, BFS)]알고리즘 문제풀기/인프런 강의 정답 2022. 4. 29. 19:56
나의정답. 전위순회
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> using namespace std; void DFS(int node) { if (node > 7) return; else { printf("%d ", node); DFS(node * 2); DFS(node * 2 + 1); } } int main(int argc, char** argv) { //freopen("input.txt", "rt", stdin); DFS(1); }
나의정답. 중위순회
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> using namespace std; void DFS(int node) { if (node > 7) return; else { DFS(node * 2); printf("%d ", node); DFS(node * 2 + 1); } } int main(int argc, char** argv) { //freopen("input.txt", "rt", stdin); DFS(1); }
나의정답. 후위순회
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> using namespace std; void DFS(int node) { if (node > 7) return; else { DFS(node * 2); DFS(node * 2 + 1); printf("%d ", node); } } int main(int argc, char** argv) { //freopen("input.txt", "rt", stdin); DFS(1); }
'알고리즘 문제풀기 > 인프런 강의 정답' 카테고리의 다른 글
60. 합이 같은 부분 집합 (아마존 인터뷰 문제 : DFS 완전탐색) [재귀 & 깊이/넓이 우선탐색(DFS, BFS)] (0) 2022.05.03 59. 부분집합 (MS 인터뷰 문제 : DFS 완전탐색) [재귀 & 깊이/넓이 우선탐색(DFS, BFS)] (0) 2022.05.02 57. 재귀함수(스택)를 이용한 2진수 출력 [재귀 & 깊이/넓이 우선탐색(DFS, BFS)] (0) 2022.04.27 56. 재귀함수 분석 (스택을 이용하는 재귀) [재귀 & 깊이/넓이 우선탐색(DFS, BFS)] (0) 2022.04.27 55. 기차운행 (스택 자료구조 응용) [정렬 & 이분탐색(결정알고리즘) & 투포인트 알고리즘 & 스택] (0) 2022.04.25