#include
#include
static int binary_search(int a[], int low, int high)
{
int mid;
int value = 5;
while (low < high) {
mid = (low + high) / 2;
if (a[mid] == value)
return 1;
else if (a[mid] > value)
high = mid - 1;
else
low = mid + 1;
}
return 0;
}
int main(void)
{
int a[10];
int i;
int result;
for (i = 0; i < 10; i++)
a[i] = i;
result = binary_search(a, 0, 9);
printf("result = %d\n", result);
return 0;
}
阅读(515) | 评论(0) | 转发(0) |