该适用在有序的序列中查找
int binary_search(int arr[],int key,int n){
int low=0,high=n-1;
int mid;
while(low<=high){
mid=(low+high)/2;
if(arr[mid]<key){
low=mid+1;
}else if(arr[mid]>key){
high=mid-1;
}else{
return mid;
}
}
return -1; //not found
}