-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinear_Search.cpp
More file actions
63 lines (56 loc) · 1.04 KB
/
Linear_Search.cpp
File metadata and controls
63 lines (56 loc) · 1.04 KB
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
///Time Complexity: O(n) for the average case
/*
Auther : Abdullah Al Masum
*/
#include <bits/stdc++.h>
using namespace std;
#define MAXX 10000000
int Arr[MAXX];
// void takeInput()
// {
// int size;
// global findValue;
// cin >> size;
// for (int i = 0; i < size; i++)
// {
// cin >> Arr[i];
// }
// cin >> findValue;
// }
void printArray(int A[], int N)
{
for (int i = 0; i < N; i++)
{
cout << A[i] << " ";
}
cout << endl;
}
void linearSearch(int Arr[], int N, int find)
{
for (int i = 0; i < N; i++)
{
if (Arr[i] == find)
{
cout << "Value found at: " << i << "th index" << endl;
}
}
}
int main()
{
//takeInput();
int size, findValue;
cin >> size;
for (int i = 0; i < size; i++)
{
cin >> Arr[i];
}
cin >> findValue;
linearSearch(Arr, size, findValue);
cout << "Here array is started from 0 index" << endl;
printArray(Arr, size);
return 0;
}
// Input for Linear linearSearch
// 5
// 5 4 6 9 1
// 9