#include<stdio.h>
int main()
{
int a[20];
int n;
int i;
int low,high,mid;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int key;
scanf("%d",&key);
low=0;high=n-1;
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]==key)
{
printf("%d",mid);
break;
}
else if(a[mid]<key)
low=mid+1;
else
high=mid-1;
}
if(low>high)
printf("None");
return 0;
}
二分查找
最新推荐文章于 2024-09-04 21:39:45 发布