-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path38-circular_queue.cpp
More file actions
78 lines (76 loc) · 1.01 KB
/
38-circular_queue.cpp
File metadata and controls
78 lines (76 loc) · 1.01 KB
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>
#include<stdlib.h>
#define size 5
using namespace std;
class queue
{
private:
int i,s[10],f,r,count;
public:
int item;
queue()
{
r=-1;
f=0;
count=0;
}
void push()
{
if(count==size)
cout<<"queue full \n";
else
{
r=(r+1)%size;
s[r]=item;
count++;
}
}
void pop()
{
if(count==0)
cout<<"queue empty \n";
else
{
f=(f+1)%size;
count--;
}
}
void display()
{
if(count==0)
cout<<"queue empty \n";
else
{
int j=f;
for(i=1;i<=count;i++)
{
cout<<s[j]<< endl;
j=(j+1)%size;
}
}
}
};
int main()
{
int choice;
queue ob;
for(;;)
{
cout<<"1:push\n2:pop\n3:display \n4:exit"<<endl;
cout<<"Enter choice";
cin>>choice;
switch(choice)
{
case 1: cout<<"enter item to be inserted";
cin>>ob.item;
ob.push();
break;
case 2: ob.pop();
break;
case 3:ob.display();
break;
default:exit(0);
}
}
return 0;
}