Binary search
Posted In:
Codeings
.
By Caztial
#include
#include
#difine N 10
int V[N];
void bsearch(int V[N]);
void input(int V[N]);
void output(int V[N]);
void main()
{
input(V);
bsearch(V);
output(V);
getch();
}
void bsearch(int bs[N])
{
bsort(I);
int high,low,key,mid=0;
printf("Input Number to Search\t");
scanf("%d",&key);
low=1; high=N;
while(mid!=key)
{
if(low>=high)
{ printf("Search Can't Befound");
break;
}
else
{
mid=(low+high)/2;
if(bs[mid]>key)
{
high=mid-1; }
else
{
} low=mid+1; }
}
if(low<=high)
printf("loaction is %d",mid);
getch();
}

0 Responses to Binary search
Something to say?