int BinaryFind(int arr[], int size, int to_find){
int left = 0;
int right = size - 1;
while (left <= right){
int mid = (left + right) / 2;
if (to_find < arr[mid]){
right = mid - 1;
}
else if (to_find>arr[mid]){
left = mid + 1;
}
else{
return mid;
}
}
return -1;
}
int main(){
int arr[] = { 9, 5, 2, 7, 6, 10 };
int to_find = 2;
int size = sizeof(arr) / sizeof(arr[0]);
int i = BinaryFind(arr, size,to_find);
if (i == -1){
printf("没找到%d\n");
}
else{
printf("找到了,下标是%d\n", i);
}
return 0;
}