指针实现:
int research(int *a, int key, int length)
{
assert(a);
int *p = a;
int *b = p + length - 1;
while (b >= p)
{
int c = (b - p) / 2;
if (*(p + c) == key)
return key;
else if (*(p + c) < key)
p = p+c+1;
else
b = b-c-1;
}
指针实现:
int research(int *a, int key, int length)
{
assert(a);
int *p = a;
int *b = p + length - 1;
while (b >= p)
{
int c = (b - p) / 2;
if (*(p + c) == key)
return key;
else if (*(p + c) < key)
p = p+c+1;
else
b = b-c-1;
}