折半查找
int arr[] = { 23, 37, 41, 55, 64, 75, 83, 99, 101 };
int t;
cin >> t;
int low = 0, high = sizeof(arr) / sizeof(arr[0]);
int mid = 0;
while (low <= high)
{
mid = (low + high) / 2;
if (arr[mid] > t)
{
cout << "比t大\n";
high = mid;
}
else if (arr[mid] == t)
{
cout << "找到了, 第 " << mid + 1 << " 个\n";
break;
}
else
{
cout << "比t小\n";
low = mid;
}
}