代码及其注释:
#include <iostream>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <stack>
#include <set>
#include <queue>
using namespace std;
stringstream ss;
typedef pair<int, int> PII;
typedef long long ll;
const int N = 35;
int n;
int post[N];
void dfs(int u)
{
if(u>n) return;
// 递归的进行左右子树遍历, 按遍历的种类进行输入, 即可得到树的层序遍历
// 若是输入前序遍历, 则在dfs前输入节点
// 若是中序, 则在中间输入节点
// 若是后序遍历, 则在dfs后进行输入
// 前序遍历 cin>>post[u];
dfs(u*2);
// 中序遍历 cin>>post[u];
dfs(u*2+1);
// 后序遍历 cin>>post[u];
cin>>post[u];
}
int main()
{
cin>>n;
dfs(1);
for(int i = 1; i<=n; i++)
{
if(i == 1) cout<<post[i];
else cout<<" "<<post[i];
}
}