#include
using namespace std;
int main()
{
void binarysearch(int[],int);
int a[]={2,3,6,11,20,25,33,36,56,58,59,69,76,86,89,99};
int i;
for(i=0;i<16;i++)
{
cout< }
cout<
cin>>no;
cout<<"input the number:"<
for(i=0;i
cout<<"now implement the search:"<
binarysearch(a,b[i]);
}
return 0;
}
void binarysearch(int a[],int key)
{
int low=0,high=15,mid;int found=0;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==key) found=1;
else if(a[mid]
else
high=mid-1;
}
if(found)
cout<
cout<
if(a[mid]==key) found=1;改为:
if(a[mid]==key) { found=1;break;}
#include
using namespace std;
int main()
{
void binarysearch(int[],int);
int a[]={2,3,6,11,20,25,33,36,56,58,59,69,76,86,89,99};
int i;
for(i=0;i<16;i++)
{
cout< }
cout<
cin>>no;
int b[20];
for(i=0;i
cin>>b[i];
}
cout<<"now implement the search:"<
binarysearch(a,b[i]);
}
cout<
}
void binarysearch(int a[],int key)
{
int low=0,high=15,mid;int found=0;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==key)
{
found=1;
break;
}
else if(a[mid]
low=mid+1;
}
else
{
high=mid-1;
}
}
if(found)
{
cout<
else
{
cout<
}
////////////////////调试过完全OK的