I hope you have read this page: http://terminalcoders.blogspot.com/2014/07/searching.html. If you didn't read it, please read it before using the source code.
#include <iostream>
using namespace std;
class OLS
{
int list[256], n, i, k;
public:
void read()
{
cout<<"Enter the number of items: ";
cin>>n;
cout<<"Enter "<<n<<" Items in ascending order: ";
for(i=0;i<n;i++)
{
cin>>list[i];
}
cout<<"Enter key to search: ";
cin>>k;
o_l_s();
}
void o_l_s()
{
i=0;
while(i<n && k>list[i])
{
i++;
}
if(list[i]==k)
{
cout<<"Key has found!!!";
}
else
{
cout<<"Key hasn't found!!!";
}
}
};
int main()
{
OLS o;
o.read();
}
