DataStructureCImpl:在顺序表中查找元素 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【meiwen.anslib.com - 电脑资料】

   

// _DataStructure_C_Impl:Search#include<stdio.h>#include<stdlib.h>#define MaxSize 100#define IndexSize 20typedef int KeyType;//元素的定义typedef struct{	KeyType key;}DataType;//顺序表的类型定义typedef struct{	DataType list[MaxSize];	int length;}SSTable;//索引表的类型定义typedef struct{	KeyType maxkey;	int index;}IndexTable[IndexSize];//在顺序表中查找关键字为x的元素,如果找到返回该元素在表中的位置,否则返回0int SeqSearch(SSTable S,DataType x){	int i=0;	while(i<s.length&&s.list[i].key!=x.key) .key="" datatype="" else="" i="S.length;" int="" return="" sstable="">x.key)		i--;	return i;}//在有序顺序表中折半查找关键字为x的元素,如果找到返回该元素在表中的位置,否则返回0int BinarySearch(SSTable S,DataType x){	int low,high,mid;	low=0;				//设置待查找元素范围的下界和上界	high=S.length-1;	while(low<=high){		mid=(low+high)/2;		if(S.list[mid].key==x.key)		//如果找到元素,则返回该元素所在的位置			return mid+1;		else if(S.list[mid].key<x.key) .key="" else="" low="mid+1;">x.key)	//如果mid所指示的元素大于关键字,则修改high指针			high=mid-1;	}	return 0;}//在主表S中查找关键字为x的元素,T为索引表,

DataStructureCImpl:在顺序表中查找元素

电脑资料

DataStructureCImpl:在顺序表中查找元素》(http://meiwen.anslib.com)。如果找到返回该元素在表中的位置,否则返回0int SeqIndexSearch(SSTable S,IndexTable T,int m,DataType x){ //分块查找;索引查找 int i,j,bl; for(i=0;i<m;i++) .maxkey="">=x.key) break; if(i>m) //如果要查找的元素不在索引顺序表中,则返回0 return 0; j=T[i].index; //要查找的元素在的主表的第j单元 if(i<m-1) .key="=x.key)" 2d="" bl="T[i+1].index-T[i].index;" datatype="" else="" indextable="" int="" pos="SeqSearch(S1,x))!=0)" pre="" return="" s1="{{123,23,34,6,8,355,32,67},8};" s2="{{11,23,32,35,39,41,45,67},8};" s3="{{6,12,23,16,21,26,41,32,37,35,48,46,49,47,52,61,59,76,68,72},20};" sstable="" t="{{23,0},{41,5},{52,10},{76,15}};" void="" x="{32};"><img alt="\" src="http://img2.shangxueba.com/img/uploadfile/20150814/16/61BC4A1149734CFEC6467FEA73E213A1.jpg" /></p></m-1)></m;i++)></x.key)></s.length&&s.list[i].key!=x.key)></stdlib.h></stdio.h>

最新文章