tijie
2023-08-18 09:23:49
发布于:广东
3阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
struct tree{
int lchild,rchild;
}t[100001];
int n;
void qian(int x){
if(x==0) return;
cout<<x<<" ";
qian(t[x].lchild);
qian(t[x].rchild);
}
void zhong(int x){
if(x==0) return;
zhong(t[x].lchild);
cout<<x<<" ";
zhong(t[x].rchild);
}
void hou(int x){
if(x==0) return;
hou(t[x].lchild);
hou(t[x].rchild);
cout<<x<<" ";
}
int main(){
cin>>n;
int a,j,k;
for(int i=1;i<=n;i++){
cin>>a>>j>>k;
t[a].lchild=j;
t[a].rchild=k;
}
qian(1);
cout<<endl;
zhong(1);
cout<<endl;
hou(1);
cout<<endl;
return 0;
}
这里空空如也
有帮助,赞一个