#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[10]={2,7,9,15, 34,56,90,96,123,345},i,x,top,bottom,mid,count=0;
cin>>x;
sort(a,a+10);
top=0;bottom=9;
while(top<=bottom)
{
mid=((top+bottom)/2);
if(a[mid]==x)
{
cout<<a[mid]<<" "<<mid<<endl;
break;
}
else
{
if(x<a[mid])
{
bottom=mid-1;
}
else
top=mid+1;
}
count++;
}
cout<<count<<endl;
return 0;
}
二分查找入门
最新推荐文章于 2024-04-01 19:33:00 发布