-
Notifications
You must be signed in to change notification settings - Fork 186
/
Insertion_Deletion_in_array
73 lines (69 loc) · 1.08 KB
/
Insertion_Deletion_in_array
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
#include<iostream>
using namespace std;
int main()
{
int queue[10], front, rear, ch, i;
char ans;
front=rear=-1;
do
{
cout<<"Press 1 to insert"<<endl;
cout<<"Press 2 to delete"<<endl;
cout<<"Press 3 to display"<<endl;
cout<<"ENTER YOUR CHOICE"<<endl;
cin>>ch;
switch(ch)
{
case 1:
if(front==-1)
{
front=0;
}
rear=rear+1;
if(rear>9)
{
cout<<"can not insert"<<endl;
rear=rear-1;
}
else
{
cout<<"enter the element"<<endl;
cin>>queue[rear];
}
break;
case 2:
if(front==-1)
{
cout<<"can not delete"<<endl;
}
else
{
cout<<"deleted information is"<<queue[front]<<endl;
front=front+1;
if(front>rear)
{
front=rear=-1;
}
}
break;
case 3:
if(front==-1)
{
cout<<"can not display"<<endl;
}
else
{
for(i=front;i<=rear;i++)
{
cout<<queue[i]<<" "<<endl;
}
}
break;
default:
cout<<"invalid choice"<<endl;
}
cout<<"wanna continue?(y/n)"<<endl;
cin>>ans;
}
while(ans=='y');
}