BST(Binary Search Tree,二叉查找树,二叉排序树)c的实现(部分函数不知如何调用)

本文展示了如何使用C语言实现二叉查找树(BST)的基本操作,包括创建、搜索、插入、删除节点,以及找到树的最小值、最大值和后继节点。提供了递归和非递归版本的函数实现,并通过主函数进行测试。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
typedef struct node 
{ 
	int key; 
	
	struct node *LChild,*RChild,*Parent; 
}BSTNode,*BSTree; 


void CreatBST(BSTree *bst);
BSTree SearchBST(BSTree bst,int key) ;
void InsertBST(BSTree *bst,int key) ;
void InsertBST2(BSTree *bst,int key) ;
BSTNode * DelBST(BSTree t,int k) ;
BSTNode * DelBST2(BSTree t,BSTNode *z) ;//主函数如何调用?
BSTNode * TreeSuccessor(BSTNode *x);//寻找后继 主函数如何调用?

void print_bst(BSTree t) {
	if (t!=NULL)
	{
		print_bst(t->LChild);
		printf(" %d ", t->key);
		print_bst(t->RChild);
	}
}

const int n = 10;

/*Creat new tree*/ 
void CreatBST(BSTree *bst) 
{ 
	int i; 
	int key; 
	*bst=NULL; 
	cout<<"请输入n(n=10)个数:"<<endl;
	scanf("%d",&key);
	InsertBST2(bst,key); 

	for(i=2;i <=n;i++) 
	{ 
		scanf("%d",&key); 
		InsertBST2(bst,key); 
	} 
	cout<<"创建成功!"<<endl;
	//return bst; 
} 


/*Search*/ //递归版本
BSTree SearchBST(BSTree bst,int key) 
{ 
	if(bst==NULL) {
	    cout<<"cannot find it"<<endl;
		return NULL; 
	}
	else 
		if(bst->key==key) 
		{
			cout<<"find i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值