谁能帮我看看代码有什么问题
  • 板块学术版
  • 楼主czk111
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/8/20 16:59
  • 上次更新2023/10/27 14:26:23
查看原帖
谁能帮我看看代码有什么问题
682044
czk111楼主2022/8/20 16:59
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
struct node{
	int data;
	struct node *left=NULL;
	struct node *right=NULL;
}*a;
void zx(struct node *t){
	if(t==NULL) return;
	zx(t->left);
	v.push_back(t->data);
	zx(t->right);
}
void hx(struct node *t){
	if(t==NULL) return;
	zx(t->left);
	zx(t->right);
	v.push_back(t->data);
}
node* cr(struct node *t,int c){
	if(!t){
		t=new struct node;
	}else{
		if(c<t->data){
			t->left=cr(t->left,c);
		}else{
			t->right=cr(t->right,c);
		}
	}
	return t;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		cr(a,t);
	}
	zx(a);
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
}
2022/8/20 16:59
加载中...