暴力枚举
2023-08-18 11:21:12
发布于:广东
2阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
struct node{
int root;
int left;
int right;
}tree[2000];
void first(int it){
if(it==0) return;
cout<<tree[it].root <<" ";
first(tree[it].left);
first(tree[it].right );
}
void first1(int it){
if(it==0) return;
first1(tree[it].left);
cout<<tree[it].root <<" ";
first1(tree[it].right );
}
void first2(int it){
if(it==0) return;
first2(tree[it].left);
first2(tree[it].right );
cout<<tree[it].root <<" ";
}
int n,m,cnt=0,sum=0,ans=0,a[1001],temp;
int main(){
cin>>n;
for(int i=0;i<n;i++){
int root;
cin>>root;
tree[root].root =root;
cin>>tree[root].left >>tree[root].right;
}
first(1);
cout<<endl;
first1(1);
cout<<endl;
first2(1);
return 0;
}
这里空空如也
有帮助,赞一个