#include<iostream>
using namespace std;
int binFind(int a[],int n,int num)
{
int start =0;
int end = n-1;
while(start <=end)
{
int mid =(start+end)/2;
if(a[mid] <num)
{
start =mid+1;
}
else if(a[mid]>num)
{
end = mid-1;
}
else if(a[mid] == num)
{
return mid+1;
}
}
}
void main()
{
int a[]={3,5,7,11,17,21,28,30,32,43};
int c=binFind(a,10,5);
}
折半查找
最新推荐文章于 2024-08-12 00:08:19 发布