-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Array_Operation.cpp
95 lines (88 loc) · 1.72 KB
/
A_Array_Operation.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
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
95
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int A[10] = {2, 4, 5, 6, 9};
int Size = 5;
void insert();
void delete_item();
void travers();
void search();
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);cout.tie(NULL);
int n;
while(n!=5)
{
printf("Select an option :\n");
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Travers\n");
printf("4.Search\n");
printf("5.Exit\n");
cin >> n;
switch (n)
{
case 1:
insert();
break;
case 2:
delete_item();
break;
case 3:
travers();
break;
case 4:
search();
break;
}
}
printf("Successfully Exit\n");
return 0;
}
void insert()
{
Size++;
int pos, val;
printf("Enter insert position :\n");
cin >> pos;
printf("Enter insert value :\n");
cin >> val;
for(int i=Size; i>=pos-1; i--)
{
A[i+1] = A[i];
}
A[pos-1] = val;
}
void delete_item()
{
int pos;
printf("Enter delete position :\n");
cin >> pos;
for(int i=pos-1; i<Size; i++)
A[i] = A[i+1];
Size--;
}
void search()
{
int val;
printf("Enter Searching Value :\n");
cin >> val;
for(int i=0; i<Size; i++)
{
if(A[i] == val)
printf("Found at position %d\n", i+1);
}
}
void travers()
{
printf("Travers is : ");
for(int i=0; i<Size; i++)
{
if(i==0)
printf("%d", A[i]);
else
printf(" %d", A[i]);
}
printf("\n");
}