#include<iostream.h>
class searching
{
private:
double *array;
int n;
public:
void input();
void linearsearch();
};
void searching::input()
{
cout<<”*********************************…
<<”This program is to implement linear search algorithm\n”
<<”*************************************…
cout<<”Enter how many numbers you are going to enter::”;
cin>>n;
array=new double[n+1];
cout<<”Now enter your elements ::\n”;
for(int i=1;i<=n;i++)
cin>>array[i];
}
void searching::linearsearch()
{
cout<<”Enter the number to be searched ::”;
double x;
cin>>x;
int i;
for(i=1;i<=n;i++)
{
if(array[i]==x)
{
cout<<”found at position ::”<<i<<endl;
break;
}
}
if(i>n)
cout<<”Not found\n”;
}
int main()
{
searching obj;
obj.input();
obj.linearsearch();
return 0;
}
No comments:
Post a Comment