数据结构折半查找法
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
}
}
else if(n<a[high])
{
count++;
high=high-1;
for(i=low;i<=high;i++)
{
count++;
if(a[i]==n)
{
adrress=i;
printf("the number %d is searched,the adrress is %d ,and search numbers is %d \n",n,adrress,count);
数据结构折半查找法
#include "stdio.h"
void main()
{
int a[10]={1,3,4,6,8,9,10,13,15,18};
int n,i,low=0,high=9;
int adrress=0,count=0;
printf("pelase input the search number:");
}
}
}
else if( a[high]==n)
printf("the number %d is searched,the adrress is %d ,and search numbers is 1 \n",n,high);
}
scanf("%d",&n);
high=high/2;
if(n>a[high])
{
count++;
low=high+1;
foFra Baidu bibliotek(i=low;i<10;i++)
{
count++;
if(a[i]==n)
{
adrress=i;
printf("the number %d is searched,the adrress is %d ,and search numbers is %d \n",n,adrress,count);
}
}
else if(n<a[high])
{
count++;
high=high-1;
for(i=low;i<=high;i++)
{
count++;
if(a[i]==n)
{
adrress=i;
printf("the number %d is searched,the adrress is %d ,and search numbers is %d \n",n,adrress,count);
数据结构折半查找法
#include "stdio.h"
void main()
{
int a[10]={1,3,4,6,8,9,10,13,15,18};
int n,i,low=0,high=9;
int adrress=0,count=0;
printf("pelase input the search number:");
}
}
}
else if( a[high]==n)
printf("the number %d is searched,the adrress is %d ,and search numbers is 1 \n",n,high);
}
scanf("%d",&n);
high=high/2;
if(n>a[high])
{
count++;
low=high+1;
foFra Baidu bibliotek(i=low;i<10;i++)
{
count++;
if(a[i]==n)
{
adrress=i;
printf("the number %d is searched,the adrress is %d ,and search numbers is %d \n",n,adrress,count);