C语言 树表的查找 代码实现

该代码定义了二叉排序树的结构,并实现了一个递归查找函数SearchBST,该函数在树中查找给定的关键字,如果找到则返回对应的结点,否则返回空指针。主函数main仅用于程序结构,实际操作在SearchBST中进行。
摘要由CSDN通过智能技术生成

#include<stdio.h>

//#include<string.h>

//#include<math.h>

#include<stdlib.h>

//函数结果状态代码

#define TRUE 1

#define FALSE 0

#define OK 1

#define ERROR 0

#define INFEASIBLE -1

#define OVERFLOW -2

#define NULL 0

#define MAXSIZE 100

//Status是函数的类型,其值是函数结果状态代码

typedef int Status;

//声明结点的类型和指向结点的指针类型

//二叉排序树

typedef struct{

KeyType key;//关键字项

InfoType otherinfo;//其他数据域

}ElemType;

typedef struct BSTNode{

ElemType data;//数据域

struct BSTNode *lchild,*rchild;//左右孩子指针

}BSTNode,*BSTree;

//二叉排序树——递归查找

BSTree SearchBST(BSTree T,KeyType key){

if((!T) || key==T->data.key) return T;

else if(key<T->data.key) return SearchBST(T->lchild,key);//在左子树中继续查找

else return SearchBST(T->rchild,key);//在右子树中继续查找

}

int main(){

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值