查找的一些函数

这篇博客详细探讨了多种查找技术,包括二叉排序树的查找操作、递归和非递归的折半查找、经典的二分查找算法,以及如何判断一个二叉树是否为二叉搜索树。此外,还介绍了在二叉排序树中查找最小值和最大值的方法,对于理解和应用这些查找算法提供了深入的解析。
摘要由CSDN通过智能技术生成

1、二叉排序树的查找

#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct BSTNode
{
	ElemType data;
	struct BSTNode  *lchild,*rchild;
}BSTNode,*BSTree;
BSTree CreateBST();/ *二叉排序树创建,由裁判实现,细节不表* /
BSTree SearchBST(BSTree T,ElemType e);
int main()
{
	BSTree T,result;
	ElemType n,e;
	T = CreateBST();
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&e);
		result = SearchBST(T,e);
		if(result) printf("%d is found\n",result->data);
		else printf("%d is not found\n",e);
	}
	return 0;
}
BSTree SearchBST(BSTree T,ElemType e)
{
	if(!T||e==T->data) return T;
	if(e<T->data) return SearchBST(T->lchild,e);
	else return SearchBST(T->rchild,e);
}

2、折半查找的递归查找操作

#include <stdio.h>
#include <stdlib.h>
typedef int KeyType;
typedef struct {
          KeyType   *data; /*表基址*/
          int     length;      /*表长
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值