AC代码
2023-07-28 14:01:51
发布于:浙江
9阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
struct node {
int left,right;
};
node tree[101];
void preorder(int root,int a){
if(root==0){
return;
}
if(a==1)
cout<<root<<" ";
preorder(tree[root].left,a);
if(a==2)
cout<<root<<" ";
preorder(tree[root].right,a);
if(a==3)
cout<<root<<" ";
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int idx, left, right;
cin >> idx >> left >> right;
tree[idx].left = left;
tree[idx].right = right;
}
int root = 1;
preorder(root,1);
cout << endl;
preorder(root,2);
cout << endl;
preorder(root,3);
return 0;
}
全部评论 1
6
2023-07-28 来自 浙江
0
有帮助,赞一个