二分核心code:
public int binary(int[] a,int key){
int l = 0,r = a.length-1;
while (l<=r){
int mid = (l+r)/2;
if(a[mid]==key) return mid;
else if (a[mid]<key) l=mid+1;
else r=mid-1;
}
return l;
}
插值核心code:
public int insert(int[] a,int key){
int l = 0,r = a.length-1;
int data = (key-a[l])/(a[r]-a[l]);
while (l<=r){
int mid = data*(r-l);
if(a[mid]==key) return mid;
else if (a[mid]<key) l=mid+1;
else r=mid-1;
}
return l;
}