针对排序好的大量数据
1 2 3 4 5 6
public static int sort2(int[] arr,int key){
int beginPost=0;
int endPost=arr.length-1;
int middlePost=(beginPost+endPost)/2;
while(arr[middlePost]==key){
return middlePost;
if(arr[middlePost]<key){
middlePost=beginPost+1;
}else if(arr[middlePost]>key){
middlePost=endPost-1;
}else{
return -1;
}
}
}