-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearSearch_array.cpp
More file actions
52 lines (40 loc) · 893 Bytes
/
linearSearch_array.cpp
File metadata and controls
52 lines (40 loc) · 893 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
52
#include<bits/stdc++.h>
using namespace std;
class Array{
public:
int A[20];
int size;
int length;
};
void display( class Array array){
int i;
cout<<"Elements Are"<<endl;
for(int i=0; i<array.length;i++){
cout<<array.A[i];
}
}
void Swap(int *x, int *y){
int temp;
temp=*x;
*x=*y;
*y=temp;
}
int Lsearch(Array *array , int key){
for (int i = 0; i < array->length; i++)
{
if(key== array->A[i]){
cout<<i<<endl;
Swap(&array->A[i],&array->A[i-1]);
cout<<i<<endl;
return 0;
}
}
return -1;
}
int main()
{
class Array arr1={{2,3,4,5,6},20,5};
Lsearch(&arr1,3);
display(arr1);
return 0;
}