binary search

int binarysearch(int a[],int value,int l,int h)
{
int middle;
if((l>=h)&&a[l]!=value)
return -1;
middle=l+(h-l)/2;
if(value==a[middle])
return middle;
if(value<a[middle])
return binarysearch(a,value,l,middle);
else
return binarysearch(a,value,middle+1,h);
}

你可能感兴趣的:(Binary search)