树的查找 修改 插入 创建

struct node{
	int data;
	node* lchild;
	node* rchild;
};

node* newnode(int v){                  //新建结点
	node* n=new node(v);
	n->lchild=n->rchild=NULL;
	return n;
}

void search(node* root,int x,int newx){     //查找 修改
	if(root==NULL){
		return ;
	}
	if(root->data==x){
		root->data=newx;
	}
	search(root->lchild,x,newx);
	search(root->rchild,x,newx);
	return ;
}

void Insert(node* & root,int x){              //插入
	if(root==NULL){
		node* n=new node(x);
		return ;
	}
	if() Insert(root->lchild,x);
	else Insert(root->rchild,x);
}

node* Creat(int* a,int n){                   //二叉树的建立
	node* root=NULL;
	for(int i=0;i<n;i++){
		Insert(root,a[i]);
	}
	return root;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务