forked from Jarvis2180/Cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray-Implementation.cpp
More file actions
94 lines (91 loc) · 2.02 KB
/
Array-Implementation.cpp
File metadata and controls
94 lines (91 loc) · 2.02 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
void insert(int a[], int n, int ele, int pos)
{
for (int i = n; i >= pos; i--)
{
a[i+1] = a[i];
}
a[pos] = ele;
}
void del(int a[], int n, int pos)
{
for (int i = pos; i <=n; i++)
a[i] = a[i+1];
}
void search(int a[], int n, int key)
{
for (int i = 0; i < n; i++)
{
if (a[i] == key)
{ cout << key << " Is At Index : " << i << endl;
return;
}
}
cout << "Not Found In Array "<<endl;
}
void PRINT(int A[], int n)
{
for (int i = 0; i < n; i++)
{
cout << A[i]<< " ";
}
}
int main()
{
int i, n, pos, ele, key;
int A[100];
int c;
int size;
cout << "Enter Size:";
cin >> n;
cout << "Enter The Elements:" << endl;
for (i = 0; i < n; i++)
{
cin >> A[i];
}
int iteration = 0;
while (iteration >= 0)
{
cout << "Enter Your Choice"<<endl;
cout<<"1-Insert"<<endl<<"2-Search"<<endl<<"3-Delete"<<endl;
cout<<"0-Exit"<<endl;
cin >> c;
if (c == 1)
{
cout<<"Insert Element In Array"<<endl;
cout << "Enter Element & Index Respectively: " << endl;
cin >> ele >> pos;
insert(A, n, ele, pos);
n++;
PRINT(A, n);
iteration++;
cout << endl;
}
if (c == 2)
{
cout<<"Search Element In Array"<<endl;
cout << "Enter Element: ";
cin >> key;
search(A, n, key);
}
if (c == 3)
{
cout<<"Delete Element From Array"<<endl;
cout << "Enter Index: " << endl;
cin >> pos;
del(A, n, pos);
n--;
PRINT(A, n);
iteration++;
cout << endl;
}
if (c == 0)
{
return 0;
}
}
return 0;
}