-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathqueuearray.cpp
78 lines (61 loc) · 1002 Bytes
/
queuearray.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
#include<iostream>
using namespace std;
int a[5],f=-1,r=-1;
display()
{
if(f!=-1)
for(int i=f;i<=r;i++)
cout<<"->"<<a[i];
}
void enqueue()
{
int item;
if(r==4)
{
cout<<"Queue is Full!!\n";
}
else if(f==-1 && r==-1)
{f++;r++;
cout<<"Enter the element:";
cin>>item;
a[r]=item;
}
else
{
cout<<"Enter the element:";
cin>>item;
r++;
a[r]=item;
}
}
void dequeue()
{
if(f==-1 && r==-1)
cout<<"Queue is Empty!!";
else
{
cout<<"Element popped out is:"<<a[f]<<"\n";
if(r==f)
{
r=-1;f=-1;
}
else
f++;
}
}
int main()
{ int c;
cout<<"\n1.Enqueue\n2.Dequeue\n0.End\n";
cin>>c;
while(c!=0)
{
switch(c)
{
case 1:enqueue();display();cout<<"\n";break;
case 2:dequeue();display();cout<<"\n";break;
default :break;
}
cout<<"\n1.Enqueue\n2.Dequeue\n0.End\n";
cin>>c;
}
}