int s(int shuzu[], int len, int x) {
int low = 0, hight = len - 1, mid;
while (low<=hight)
{
mid = (low + hight) / 2;
if (shuzu[mid] == x) return shuzu[mid];
else if (shuzu[mid] < x) hight = mid - 1;
else low = mid + 1;
}
return -1;
}
int main() {
int a[6] = { 99,8,52,66,4,27 };
int b = s(a, sizeof(a) /sizeof(int), 99);
cout << b << endl;
if (b!=-1)
{
cout << "查找" << b << "成功" << endl;
}else cout << "查找失败"<< endl;
标签:二分,int,len,查找,c++,low
From: https://www.cnblogs.com/bibody/p/17818433.html