public static int binarySearch(int []arr,int key,int left,int right) {
if(left<=right) {
int mid=(left+right)/2;
if(key>arr[mid]) {
left=mid+1;
return binarySearch(arr,key,left,right);
}else if(key==arr[mid]) {
return mid;
}else {
right=mid-1;
return binarySearch(arr,key,left,right);
}
}
return -1;
}
递归版的二分查找
最新推荐文章于 2023-05-05 21:54:08 发布