int binsearch(int *t,int k,int n)
{//t为数组,k是要查找的数,n为长度,此为升序
int low = 1,high = n,mid;
while(low<=high)
{
mid = (low+high)/2;
if(k == t[mid])
return mid;
else if(k<t[mid])
high = mid-1;
else
low = mid+1;
}
return -1;
}
二分(模板)
最新推荐文章于 2023-10-01 11:16:40 发布