Lang:G++
Edit12345678910111213141516171819202122#include<bits/stdc++.h>using namespace std;const int maxn = 1e2 + 1;int in_order[maxn], n;void build(int L, int R){if(L > R)return;int root = *min_element(in_order + L, in_order + R + 1);printf("%d ", root);int m = L;while(in_order[m] != root)m++;build(L, m - 1);build(m + 1, R);}int main(){scanf("%d", &n);for(int i = 0; i < n; i++)scanf("%d", &in_order[i]);build(0, n - 1);return 0;}