代码清单3-17(带有错误的二分查找源码)
int bisearch(char** arr, int b, int e, char* v)
{
int minIndex = b, maxIndex = e, midIndex;
while(minIndex < maxIndex)
{
midIndex = (minIndex + maxIndex) / 2;
if(strcmp(arr[midIndex], v) <= 0)
{
minIndex = midIndex;
}
else
{
maxIndex = midIndex – 1;
}
}
if(!strcmp(arr[maxIndex], v))
{
return maxIndex;
}
else
{
return -1;
}
}