pro12b by devilxscience

VIEWS: 0 PAGES: 2

									#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class linear_search
{
  private :
    int datas[10];
  public :
    linear_search()
    { int i;
        clrscr();
        for(i=0;i<10;i++)
        {
        cout << "Enter the value for item " << i+1;
        cin >> datas[i];
        }
for(i=0;i<size-1;i++)
        {
      for(int j=i+1;j<size;j++)
      {
        if(datas[i]>datas[j])
        {
            k=datas[i];
            datas[i]=datas[j];
            datas[j]=k;
        }
      }
        }
      cout<<endl;
        for(i=0;i<size;i++)
      {
          cout <<i+1 << " ->" << datas[i]<<endl;
      }

   }
   void search()
   {
     int item,i,found;
     found=0;i=0;
     cout<<"Enter the value to be search : ";
     cin>>item;
     while(found==0 && i < 10)
     {
       if(datas[i]==item)
             found=1;
       i++;
     }
     if(found==1)
       cout<<"Data you searched " << item << " is found at position" << i
<< ".";
     else
       cout<<"Data you searched " << item << " is not found.";
       }
  };
void main()
{
 char ch;
 linear_search ls1;
 do
 {
   ls1.search();
   cout << "do you want to search any more data (Y/N) : ";
   cin>>ch;
 }while(ch != 'N' && ch != 'n');
}

								
To top