二分查找递归
程序员文章站
2022-03-14 11:03:49
...
int f(int m,int n,int a[],int x)
{
if(m<=n)
{
int mid=(n+m)/2;
if(a[mid]==x) return mid+1;
else if(a[mid]<x) return f(mid+1,n,a,x);
else return f(m,mid-1,a,x);
}
else return -1;
}