标签:str ring length oid string [] dex bsp java
1.用折半查找数组元素的下标
2.但前提是数组已经排序好的
3.例:
public static void main(String ars []){
int [] number=new int []{2,6,9,45,65,88};
}
publci staic int getIndex(int [] arr,int key){
int min=0,max=arr.length,mid;
while(min<=max){
mid=(min+max)>>1;
if(key>arr[mid]){
min=mid+1;
}
else if(key<arr[mid]){
max=mid-1;
}
else {
return mid;
}
}
return -1; //要查找 的数据没有在数组 中
}
标签:str ring length oid string [] dex bsp java
原文地址:http://www.cnblogs.com/taobd/p/7044105.html