[求助]拆半查找算法
哪位大侠能帮小弟编个拆半查找算法,我在此多谢了!(越简单越好,最好有注释)
int mid=(high+low)/2;
if(x==v[mid]) return v[mid];
if(x<v[mid])
return binsearch(x,v,low,mid-1);
else
return binsearch(x,v,mid+1,high);
}
main()
{ int a[8],i,b,re;
printf("输入数组的各个元素!");
for(i=0;i<8;i++)
scanf("%d",&a[i]);
printf("输入要找的数!");
scanf("%d",&b);
re=binsearch(b,a,0,8);
printf("%d",re);
}