int BinarySort(int arr[],int n,int key)
{
if(arr==NULL||n<1)
return -1;
int left=0,right=n-1;
while(left<=right){
int mid=left+(right-left)/2;
if(arr[mid]<key)
left=mid+1;
else if(arr[mid]>key)
right=mid-1;
else
return mid;
}
return -1;
}
二分查找
最新推荐文章于 2024-10-21 22:00:00 发布