数据结构 折半查找
实例代码:
/*
名称:折半查找
语言:数据结构C语言版
编译环境:VC++ 6.0
日期: 2014-3-26
*/
#include
#include
#include
#define N 11 // 数据元素个数
typedef int KeyType; // 设关键字域为整型
typedef struct // 数据元素类型
{
KeyType key; // 关键字域
int others; // 其它部分
}ElemType;
// Search_Seq.h 静态查找表的顺序存储结构
typedef struct
{
// 数据元素存储空间基址,建表时按实际长度分配,0号单元留空
ElemType *elem;
int length; // 表长度
}SSTable;
ElemType r[N]={
{05,1},{13,2},{19,3},{21,4},
{37,5},{56,6},{64,7},{75,8},
{80,9},{88,10},{92,11}
}; // 数据元素(以教科书P219的数据为例),全局变量
// 静态查找表(顺序表和有序表)的基本操作(7个)
// 构造一个含n个数据元素的静态顺序查找表ST(数据来自全局数组r)
int Creat_Seq(SSTable *ST,int n)
{