数据结构C语言版_折半查找
/*
数据结构C语言版 折半查找
P219
编译环境:Dev-C++ 4.9.9.2
日期:2011年2月15日
*/
#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)
{
int i;
(*ST).elem