#include <stdio.h>
int binarySearch(int arr[], int low, int high, int key) {
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == key)
return mid;
else if (arr[mid] > key)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
int main() {
int arr[] = {85, 63, 52, 34, 25, 17, 6};
int n = sizeof(arr) / sizeof(arr[0]);
int key = 6;
int result = binarySearch(arr, 0, n - 1, key);
if (result != -1)
printf("元素 %d 在数组中的索引为 %d\n", key, result);
else
printf("元素 %d 不在数组中\n", key);
return 0;
}