使用二分法查找指定数据

static int binarySearch(int[] array, int value){
bubbleSortedArray(array);
int max = array.length-1;
int min = 0;
int mid = (max + min) / 2;
while(max >= min){
if(value > array[mid]){
min = mid + 1;
}
if(value < array[mid]){
max = mid - 1;
}
if(value == array[mid]){
return mid;
}
mid = (max + min) / 2;
}
return -1;
}

你可能感兴趣的:(java查找算法)