Skip to content

Commit e1c6d38

Browse files
authored
Create Insertion_Deletion_in_array
1 parent 2cd329d commit e1c6d38

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

Insertion_Deletion_in_array

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
8+
int queue[10], front, rear, ch, i;
9+
char ans;
10+
front=rear=-1;
11+
do
12+
{
13+
cout<<"Press 1 to insert"<<endl;
14+
cout<<"Press 2 to delete"<<endl;
15+
cout<<"Press 3 to display"<<endl;
16+
cout<<"ENTER YOUR CHOICE"<<endl;
17+
cin>>ch;
18+
switch(ch)
19+
{
20+
case 1:
21+
if(front==-1)
22+
{
23+
front=0;
24+
}
25+
rear=rear+1;
26+
if(rear>9)
27+
{
28+
cout<<"can not insert"<<endl;
29+
rear=rear-1;
30+
}
31+
else
32+
{
33+
cout<<"enter the element"<<endl;
34+
cin>>queue[rear];
35+
}
36+
break;
37+
case 2:
38+
if(front==-1)
39+
{
40+
cout<<"can not delete"<<endl;
41+
}
42+
else
43+
{
44+
cout<<"deleted information is"<<queue[front]<<endl;
45+
front=front+1;
46+
if(front>rear)
47+
{
48+
front=rear=-1;
49+
}
50+
}
51+
break;
52+
case 3:
53+
if(front==-1)
54+
{
55+
cout<<"can not display"<<endl;
56+
}
57+
else
58+
{
59+
for(i=front;i<=rear;i++)
60+
{
61+
cout<<queue[i]<<" "<<endl;
62+
}
63+
}
64+
break;
65+
default:
66+
cout<<"invalid choice"<<endl;
67+
}
68+
cout<<"wanna continue?(y/n)"<<endl;
69+
cin>>ans;
70+
}
71+
while(ans=='y');
72+
73+
}

0 commit comments

Comments
 (0)