编辑代码

#include <iostream>
using namespace std;
int searchSortedArray(int searchKey, int array[], int arrlen){
    int left = 0, right = arrlen - 1, keyPos = -1;
    while(left <= right){
        int mid = left + (right - left) / 2;
        if(searchKey == array[mid]){
            keyPos = mid;
            break;
        }
        else if(searchKey > array[mid]){
            right = mid - 1;
        }
        else{
            left = mid + 1;
        }
    }
    return keyPos;
}
int main() {
    int a[]={85, 63, 52, 34, 25, 17, 6};
    int n = sizeof(a) / sizeof(a[0]);
    int keyIndex = searchSortedArray(6,a,n);
    cout << keyIndex << endl;
	return 0;
}