算法不用就忘,mark
public static void binary_search(int target,int [] arr){
if (arr== null || arr.length == 0){
System.out.println("not find");
return;
}
int bottom = 0;
int top = arr.length-1;
int mid = 0;
while (true){
mid = (bottom+top)/2;
if (bottom > top) {
//not find
System.out.println("not find");
return;
}else if (target == arr[mid]){
//find target
System.out.println("find it at "+mid);
return;
}else if(target <arr[mid]){
//在左半边
top=mid-1;
}else if(target >arr[mid]){
//在右半边
bottom = mid+1;
}
}
}