插值查找分析相当于对二分查找的一种优化,让mid指针更加精确 代码1234567891011121314151617181920212223242526272829303132package 算法;public class 插值查找 { public static void main(String[] args) { int[] arr = new int[100]; for (int i = 0; i <100 ; i++) { arr[i] = i+1; } int index = insertValueSearch(arr, 0, arr.length-1, 99999); System.out.println(index); } public static int insertValueSearch(int[] arr,int left,int right,int num){ if(num<arr[left]||num>arr[right]){ return -1; } int l =left; int r = right; int mid = l + (r-l)*(num-arr[l])/(arr[r]-arr[l]); while (l<=r){ if(arr[mid]==num){ return mid; } if(arr[mid]>num){ r = mid-1; }else{ l = mid+1; } mid = l + (r-l)*(num-arr[l])/(arr[r]-arr[l]); } return -1; }}