-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular_queue_customer_service.cpp
More file actions
103 lines (77 loc) · 1.27 KB
/
Copy pathcircular_queue_customer_service.cpp
File metadata and controls
103 lines (77 loc) · 1.27 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<iostream>
using namespace std;
#define max 5
class circular{
private:
int f,r;
int cq[max];
int num,val;
public:
circular(){
f=-1;
r=-1;
}
void enqueue(){
cout<<endl<<"Enter the number";
cin>>num;
if(((r+1)%max)==f){
cout<<"\n Full";
}
else {
r=(r+1)%max;
cq[r]=num;
if(r==0){
f++;
}
}
}
void dequeue(){
if(f==-1&&r==-1){
cout<<"\n Empty";
}
else if(f==r){
val=cq[r];
f=r=-1;
}
else{
val=cq[f];
f=(f+1)%max;
}
}
void display(){
cout<<"\n The queue is :";
int temp;
if(f==-1&&r==-1){
cout<<"\n Empty";
}
else {
for(temp=f;temp<=r;temp++){
cout<<endl<<cq[(temp)%max];
}
}
}
};
int main(){
circular c;
int i,choice;
do{
cout<<"\n Enter your choice"<<endl<<"1 - enqueue"<<endl<<"2 - dequeue"<<endl<<"3 - display";
cin>>i;
switch(i)
{
case 1:
c.enqueue();
break;
case 2:
c.dequeue();
break;
case 3:
c.display();
break;
default:
cout<<"\n Enter a valid option";
}
cout<<"\n Enter 1 to continue";
cin>>choice;
}while(choice==1);
}