自用资料
#include <bits/stdc++.h>
using namespace std;
const int N = 40;
int n;
int l[N], r[N];
void dfs(int u)
{
if(!u) return;
dfs(l[u]);
dfs(r[u]);
cout << u << " ";
}
int main()
{
cin >> n;
int root, last = 0, type;
stack<int> stk;
for(int i = 0;i < 2 * n;i ++)
{
string op;
cin >> op;
if(op == "Push")
{
int x;
cin >> x;
if(!last) root = x;
else{
if(type == 0) l[last] = x;
else r[last] = x;
}
stk.push(x);
type = 0;
last = x;
}else
{
last = stk.top();
stk.pop();
type = 1;
}
}
dfs(root);
return 0;
}