#include "stdio.h"
int BinarySearch(const int A[], int key, int N)
{
int Low, Mid, High;
Low = 0;
High = N - 1;
while(Low <= High)
{
Mid = (Low + High) / 2;
if(A[Mid] < key)
Low = Mid + 1;
else if(A[Mid] > key)
High = Mid - 1;
else
return Mid;
}
return -1;
}
//测试:
int main()
{
int a[] = {-2, -4, 0, 5, 11, 13};
printf("BinarySearch: %d\n", BinarySearch(a, 13, size));
return 0;
}