int Recurrence_Search_Bin(SSTable ST,KeyType key,int floor,int roof){
//用递归方法在有序表ST中二分查找关键字为key的数据元素,若找到则返回该元素在表中的位置,否则返回0
if(floor > roof) return 0;
int mid = (floor + roof) / 2;
if(key == ST.elem[mid].key) return mid;
else if (key < ST.elem[mid].key) return Recurrence_Search_Bin(ST,key,floor,mid - 1);
else return Recurrence_Search_Bin(ST,key,mid + 1,roof);
}//Recurrence_Search_Bin
用递归方法在有序表中二分查找(折半查找)
最新推荐文章于 2023-06-25 18:31:12 发布