-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray_ds.cpp
91 lines (85 loc) · 1.55 KB
/
array_ds.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
#include <iostream>
#include<conio.h>
using namespace std;
int a[50], n;
void insertion(int num, int pos){
for(int j=n;j>=pos;j--){
a[j] = a[j-1];
}
a[pos] = num;
cout<<"New array:-\n";
for(int i=0;i<=n;i++){
cout<<a[i];
}
}
void searching(int search){
for(int i=0;i<n;i++){
if(a[i]==search){
cout<<"Element present at "<<i+1;
break;
}
}
}
void deleting(int del){
for(int i=0;i<n;i++){
if(a[i]==del){
for(int j=i;j<n;j++){
a[j] = a[j+1];
}
break;
}
}
cout<<"New array:-\n";
for(int i=0;i<n;i++){
cout<<a[i];
}
}
int main(){
int search, num, pos, del, ch;
cout<<"\nEnter the number of elements = ";
cin>>n;
cout<<"\nEnter the elements of array:-\n";
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<"\nChoose from the following:- \n1. Insertion\n2. Search\n3. Deletion\n4. Quit\n";
do
{
cout<<"\n\nEnter choice:-\n";
cin>>ch;
switch(ch){
case 1:{
cout<<"\nEnter the number to inserted :-\n";
cin>>num;
cout<<"Enter the position:-\n";
cin>>pos;
insertion(num, pos);
break;
}
case 2: {
cout<<"\nEnter the element to be searched = ";
cin>>search;
searching(search);
break;
}
case 3: {
cout<<"\nEnter the element to be deleted = ";
cin>>del;
deleting(del);
break;
}
case 4: {
cout<<"\nExit\n";
exit(1);
break;
}
default: {
cout<<"\nInvalid choice\n";
break;
}
}
}
while (ch!=5);
getch();
return 0;
}