题解
2023-07-28 13:47:57
发布于:浙江
4阅读
0回复
0点赞
/*
--------lzhledfz--------
*/
#include<bits/stdc++.h>
using namespace std;
struct am{
int left,right;
};
am tree[1010];
void a(int root){
if(root==0)return ;
cout<<root<<" ";
a(tree[root].left);
a(tree[root].right);
}
void b(int root){
if(root==0)return ;
b(tree[root].left);
cout<<root<<" ";
b(tree[root].right);
}
void c(int root){
if(root==0)return ;
c(tree[root].left);
c(tree[root].right);
cout<<root<<" ";
}
int main(){
int n,root=1;
cin>>n;
for(int i=0;i<n;i++){
int l,r,v;
cin>>v>>l>>r;
tree[v].left=l;
tree[v].right=r;
}
a(root);
cout<<endl;
b(root);
cout<<endl;
c(root);
cout<<endl;
return 0;
}
这里空空如也
有帮助,赞一个