题面
Write a function binarySearch(a, n, x) that searches integer array of length , and returns the index of ( if can not be found in ).
Assume elements of are entered in descending order, and the value of evey element is unique.
Write a program to call binarySearch(a, n, x).
/***************************************************************/
/* */
/* DON'T MODIFY main function ANYWAY! */
/* */
/***************************************************************/
#include <stdio.h>
int binarySearch(int a[], int n, int x) {
// TODO: your function definition
}
/***************************************************************/
#define N 100000
int a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
//********** binarySearch is called here *************
int q, x;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &x);
printf("%d\n", binarySearch(a, n, x));
}
//**************************************************
return 0;
}
提示
Note that the function binarySearch(a, n, x) will be called many times in the test.