int Search(int v[],int data,int N)
{
int start=0,end=N-1;
int mid=0;
mid = (start+end)/2;
if( (data < v[start]) || (data> v[end]) )
{
puts("NOT FOUND"); return -1;}
while(end-start>2)
{
if(data < v[mid])
end= mid -1;
else
start= mid + 1;
}
if(v[start] ==data)
{
puts("FOUND");
return start;
}
if(v[end] ==data)
{
puts("FOUND");
return end;
}
if(v[mid] ==data)
{
puts("FOUND");
return mid;
}
puts("NOT FOUND");
return -1;
}
No comments:
Post a Comment