我在java中为二进制搜索编写了以下代码:
import java.util.Arrays;
class BinarySearch {
public static int binarySearch(double[] arr, double x, int high, int low) {
int mid=(high+low)/2;
if(high==low || low==mid || high==mid) {
return -1;
}
if(arr[mid]<x) {
return binarySearch(arr, x, high, mid);
}
else if(arr[mid]>x) {
return binarySearch(arr, x, mid, low);
}
else if(arr[mid]==x) {
return mid;
}
return -1;
}
public static void main(String args[]) {
int n=1000;
double array[] = new double[n];
for (int i=0; i<100; i++) {
for (int k = 0; k …Run Code Online (Sandbox Code Playgroud)