6-173 二分查找的关键字比较次数
6-173 二分查找的关键字比较次数 - (3+2)专科段数据结构专项练习(2024版) (pintia.cn)
int CountSearchTimes(int a[], int low, int high, int x) {int time=0;while(low <= high){int mid=(low+high)/2;time++;if(a[mid]==x)return time;else if(a[mid]>x)high=mid-1;else low=mid+1;}return 0;
}