-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlinear.cpp
48 lines (47 loc) · 874 Bytes
/
linear.cpp
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
#include <iostream>
#include <vector>
using namespace std;
template<class t>
void linearsearch(vector<t> input,int find)
{
register int i=0;
int flag = 0;
for(i=0;i<input.size();i++)
{
if(find == input[i])
{
flag =1;
break;
}
else
{
flag=0;
}
}
if(flag==0)
{
cout << "Element not found"<<endl;
}
else if(flag==1)
{
cout << "Element found!!!"<<endl;
}
}
int main()
{
int n; //size of the array
cout << "Enter the number of elements you want in the array"<<endl;
cin >> n;
int i=0;
vector<int> arr;
int num;
for(i=0;i<n;i++)
{
cin >> num;
arr.push_back(num);
}
int f; //element to find
cout << "enter the element to found"<<endl;
cin >> f;
linearsearch(arr,f);
}