请教折半查找法的算法
求:折半查找的递归和非递归算法;主要是递归算法,
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);
}
[此贴子已经被作者于2005-11-19 22:01:18编辑过]