Hello, i'm stuck with a problem on binary search. I need to compare a string with an array of type string.
It is changing the position from which the string should be read but z compare is not successful.
here's my code.
Any help would be appreciated.
thanks in advance.
int n=500;
string name;
string element;
cout<<"\nEnter institute name:";
cin>>element;
int l,u,m, flag = 0;
l = 0;
u = n-1;
while(l <= u) {
m =( (l+u)/2);
cout<<"Searching at location"<< m<<endl;
cout<<Institute[m]<<"HI"<<endl;
if(element==Institute[m])
{
cout << "\nMatch found at " << i << endl;
flag =1;
break;
}
else
{
if(Institute[m] < element)
l = m+1;
else
u = m-1;
}
}
if( flag == 0)
cout<<"\nElement not found\n";