#include "stdio.h"
int Binsearch_2(int A[],int Key,int low,int high)
{//折半查找——二分查找——基于有序序列上的查找——递归写法
//int mid = (low + high) / 2; //如果是上亿的存储空间,那么先加法可能有溢出
int mid=low+(high-low)/2; //这个公式比上面的 优点是减少了溢出的可能性!
if (A[mid] == Key)return mid;
else if (A[mid] > Key) return Binsearch_2(A, Key, low, mid - 1);
else return Binsearch_2(A, Key, mid + 1, high);
}
void main()
{
int A[] = { 10,12,15,18,20,21,33,44,55,58,66,69 };
int index=Binsearch_2(A,15,0,(sizeof(A)/4));
printf("折半查找——二分查找——基于有序序列上的查找——递归写法:新奥尔良Q503113831\n");
printf("数组从零开始查到的下标是:%d,输出信息:%d", index, A[index]);
getchar();
}