forked from KISHOREMUTHU/Data-Structures-And-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_search.cpp
More file actions
51 lines (32 loc) · 790 Bytes
/
linear_search.cpp
File metadata and controls
51 lines (32 loc) · 790 Bytes
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
# Data-Structures-And-Algorithms
Here I will post my regular DSA problems
// Linear search implementation
#include<iostream>
using namespace std;
#include<conio.h>
#include<stdlib.h>
class lin_search{
public:
int a[100],n,i,x;
lin_search(){
cout<<"Enter number of array elements: ";
cin>>n;
cout<<"Enter the array elements: ";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"Enter the element to search: ";
cin>>x;
for(i=0;i<n;i++){
if(a[i]==x){
cout<<"Found at index "<<i<<endl;
exit(0);
}
}
cout<<"Not found"<<endl;
}
};
int main (){
lin_search l;
return 0;
}