#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
BST(Binary Search Tree,二叉查找树,二叉排序树)c的实现(部分函数不知如何调用)
最新推荐文章于 2022-10-20 18:36:10 发布
本文展示了如何使用C语言实现二叉查找树(BST)的基本操作,包括创建、搜索、插入、删除节点,以及找到树的最小值、最大值和后继节点。提供了递归和非递归版本的函数实现,并通过主函数进行测试。
摘要由CSDN通过智能技术生成