今日份分享:使用C语言实现静态查找表中的顺序查找和折半查找,并分析时间长短
Search.h文件
#define OK 1
#define ERROR -1
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAXSIZE 100
typedef int KeyType;
typedef int ElemType;
typedef struct{
ElemType data[10];
KeyType key;
}Node;
typedef struct{
Node elem[MAXSIZE];
int length;
}SSTable;
int CreateTable(SSTable &ST,int n);
void OutputTable(SSTable ST);
int Search_Seq(SSTable ST,KeyType key);
int Search_Bin(SSTable ST,KeyType key);
主要函数:
① 顺序表的创建
int CreateTable(SSTable &ST,int n)
{
int i;
ST.length=n;
for(i=1;i<=n;i++)
{
printf("输入关键字:");
scanf("%d",&ST.elem[i].key);
print