#include <iostream>
using namespace std;
const int SIZE=50;
int main()
{
int arr[SIZE];
int no,key;
cin>>no;
for(int i=0;i<no;i++)
cin>>arr[i];
int min=0,max=no-1;
int mid=(min+max)/2;
cin>>key;
while(key!=arr[mid])
{
if(key>arr[mid])
min=mid+1;
else
max=mid-1;
if(max<min)
{
cout<<"no find"<<endl;
break;
}
mid=(min+max)/2;
}
if(max>=min)
{
cout<<mid<<endl;
}
return 0;
}
折半查找
最新推荐文章于 2024-08-12 00:08:19 发布