public static int insertValueSearch(int[] arr, int num) {
return insertValueSearch(arr, 0, arr.length - 1, num);
}
public static int insertValueSearch(int[] arr, int left, int right, int num) {
//如果没有找到
if (left > right || num < arr[0] || num > arr[arr.length - 1]) {
return -1;
}
//获取中间索引
int mid = left + (num - arr[left]) / (arr[right] - arr[left]) * (right - left);
//往左边递归找
if (num < arr[mid]) {
return insertValueSearch(arr, left, mid - 1, num);
}
//往右边递归找
else if (num > arr[mid]) {
return insertValueSearch(arr, mid + 1, right, num);
}
//数据位置找到
else {
return mid;
}
}