免费 网站模板,小程序开发制作费用,vps网站目录显示灰色的,网站建设工具哪家好折半查找又为二分查找#xff0c;对待查找的列表有两个要求#xff1a;1.必须采用顺序存储结构。 2.必须按关键字大小顺序排列。 #includestdio.h
#define Max 100
typedef struct {int key;int other;
}RecordType;
typedef struct {RecordType r[Max];int lenght;
… 折半查找又为二分查找对待查找的列表有两个要求1.必须采用顺序存储结构。 2.必须按关键字大小顺序排列。 #includestdio.h
#define Max 100
typedef struct {int key;int other;
}RecordType;
typedef struct {RecordType r[Max];int lenght;
}Recordlist;
int SeqSearch(Recordlist l,int k)
{int low1,highl.lenght,mid;while(lowhigh){mid(lowhigh)/2;if(kl.r[mid].key)return (mid);else if(kl.r[mid].key) highmid-1;else lowmid1;}return 0;
}
int main()
{Recordlist l;int k,i;scanf(%d,l.lenght);for(i0;il.lenght;i){scanf(%d,l.r[i].key);}scanf(%d,k);iSeqSearch(l,k);if(i!0)printf(%d\n,i1);else printf(no\n);return 0;
}