二分法查找
int[] arr={-12,-1,21,48,56,79,123,487,666,987};
int dest=-12;
int head=0;
int end=arr.length-1;
boolean isFlag=false;
while(head<=end){
int maddle=(end+head)/2;
if(dest==arr[maddle]){
System.out.println("找到了指定的元素,位置是:"+maddle);
isFlag=true;
break;
}else if(dest<arr[maddle]){//在左边的情况
end=maddle-1;
}else{//在右边的情况
head=maddle+1;
}
}
if(isFlag==false){
System.out.println("没有找到哦!");
}