废话不多说,上代码:
#include <bits/stdc++.h>
using namespace std;
char c,c1;
struct Node {
char l,r;
}t[1000010];
void dfs(char x){
if(x=='*'){
return;
}
cout<<x;
if(t[x].l) dfs(t[x].l);
if(t[x].r) dfs(t[x].r);
}
int main(){
int n;
cin>>n;
cin>>c;
cin>>t[1].l;
cin>>t[1].r;
for(int i=2;i<=n;i++){
cin>>c1;
cin>>t[i].l;
cin>>t[i].r;
}
dfs(c);
return 0;
}
题目的样例数据,只输出a......