News
  • Submission of Theory Assignments 6,7,8 of OS on 1st April
  • Case Study Presentation of OS on 4st April
  • CN and PNS Journal Submission on 6th April

DS (RM) Program - Sequential Search



 DS (RM) Program - Sequential Search







 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define SIZE 25

int n=0;
int seqsear(int[], int, int*);

void main()
{
 int i, flag, key,*locn, option;
 int L[SIZE];

 clrscr();

 while(1)
 {
  cout<<"\n1. input unordered list : \n";
  cout<<"2. Search for key using sequential search : \n";
  cout<<"3. Quit \n";
cout<<"\n Enter Option : ";
cin>>option;

switch(option)
{
case 1:
cout<<"\n\nno.of Elements ? ";
cin>>n;
cout<<"\nInput list of elements : ";
for(i=0; i<n; i++)
{
L[i] = 0;
cin>>L[i];
}
break;

case 2:
cout<<"\n\nEnter Search key !\n";
cin>>key;
flag=seqsear(L,key,locn);
if(flag==1)
{
cout<<"\n Data is Found ...\n";
cout<<"Location is : ";
cout<<*locn+1;
}
else
    cout<<"\n Data is Not Found ...";
   break;
  case 3:
   exit(0);

  default:
   cout<<"Illegal option ...\n";
  }
 }
 getch();
}
int seqsear(int list1[], int tar, int *locn1)
{
  int looker;
  looker = 0;
  while(looker< 10 && tar!=list1[looker])
  {
   looker++;
  }
  *locn1 = looker;
  return (tar==list1[looker]);
}
Output:

1. input unordered list :
2. Search for key using sequential search :
3. Quit

 Enter Option : 1
no.of Elements ? 4

Input list of elements : 34
86
12
55

1. input unordered list :
2. Search for key using sequential search :
3. Quit

 Enter Option : 2
Enter Search key !
12

 Data is Found ...
Location is : 3
1. input unordered list :
2. Search for key using sequential search :
3. Quit

 Enter Option :3


© Copyright NMITD MCA Notes Published.. Blogger Templates
Back To Top