1234567890
2024-08-10 16:31:40
发布于:广东
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int a[N], n;
void preorder(int x){
cout << a[x] << " ";
if(2x <= n) preorder(2x);
if(2x+1 <= n) preorder(2x+1);
}
int main(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
preorder(1);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int a[N], n;
void postOrder(int x){
if(2x <= n) postOrder(2x);
cout << a[x] << " ";
if(2x+1 <= n) postOrder(2x+1);
}
int main(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
postOrder(1);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int a[N], n;
void postOrder(int x){
if(2x <= n) postOrder(2x);
if(2x+1 <= n) postOrder(2x+1);
cout << a[x] << " ";
}
int main(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
postOrder(1);
return 0;
}
这里空空如也
有帮助,赞一个