我正在研究递归问题,我要调用它,但它显示如下
import java.util.Arrays;
public class BinarySearch {
public static int binarySearch(int [] list, int key){
int low = 0;
int high = list.length -1;
return binarySearch(list, key, low ,high);
}
public static int binarySearch(int [] list, int key, int low, int high){
if(low > high){
return (-low -1);}
int mid = (low + high) / 2;
if(key < list[mid])
return binarySearch(list, key, low, mid - 1);
else if(key == list[mid])
return mid;
else
return binarySearch(list, key, mid + 1, high);
}
public static void main (String [] args){
int [] list = {'1', '2','4','5'};
binarySearch(list, 4);
System.out.println(Arrays.toString(list));
}
}
输出:[49、50、52、53]
我应该怎么做才能使它正确?