int binsearch(int arr[],int n,int key){
int left=0,right=n-1;
while(left<right){
int mid=(left+right)/2;
if(key<arr[mid]){
right=mid-1;
}else if(key>arr[mid]){
left=mid+1;
}else{
return mid;
}
}
return -1;
}
二分法查找数组的数字
最新推荐文章于 2024-01-28 14:53:03 发布