seqsearch.c

来自「一些查找和排序的算法源码」· C语言 代码 · 共 38 行

C
38
字号
#include <stdio.h>

#define seqListDataSize	50

typedef seqListDataType	int
typedef struct 
{
	recordDataType element[recordDataSize];
	int length;
}seqList

int serchSeqList(seqList *l,seqListDataType key)
{
	l.element[0]=key;
	i=l.length;
	while(l.element[i]!=key)
		i--;
	return i;
}

int binSerchSeqList(seqList *l,seqListDataType key)
{
	int low,high,mid;
	low=1;
	high=l.length;
	while(low<=high)
	{
		mid=(low+high)/2;
		if(key==l.element[mid])
			return mid;
		if(key>l.element[mid])
			low=mid+1;
		else
			high=mid-1;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?