二分查找的递归算法
#include<cstdio>
#include<algorithm>
using namespace std;
int binarySearch(int A[],int left,int right,int key){
int mid = left + (right-left)/2;
if(A[mid]==key) return mid;
else if(A[mid]<key) return binarySearch(A,mid+1,right,key);
else {
return binarySearch(A,left,mid-1,key);
}
}
int main(){
int A[10] = {4,5,1,3,9,11,2,0,23,10};
printf("%d\n%d",binarySearch(A,0,9,23),A[binarySearch(A,0,9,23)]);
}