Baekjoon 5639
이진 검색 트리


QUESTION ❔



CODE ⌨️

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> preOrder;

int num;

void postOrder(int start, int end)
{
	if (start > end) return;

	int rootNum = preOrder[start];
	int last = end;

	while (preOrder[last] > rootNum)
	{
		last--;
	}

	postOrder(start + 1, last);
	postOrder(last + 1, end);

	cout << rootNum << "\n";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	while (cin >> num)
	{
		preOrder.push_back(num);
	}

	postOrder(0, preOrder.size() - 1);

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

Tree재귀 관련 문제였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.