//折半查找算法,找不到返回0 int Search_Bin(SSTable &ST, int key) { //--------补充代码--Start------ //--------补充代码--End------- }
时间: 2023-11-23 21:07:38 浏览: 86
折半查找算法
以下是折半查找算法的实现,如果找不到则返回0:
```c++
int Search_Bin(SSTable &ST, int key)
{
int low = 1, high = ST.length, mid;
while (low <= high)
{
mid = (low + high) / 2;
if (ST.R[mid].key == key)
{
return mid;
}
else if (ST.R[mid].key > key)
{
high = mid - 1;
}
else
{
low = mid + 1;
}
}
return 0;
}
```
阅读全文