forked from manish-kumar5848/Code_queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.cpp
108 lines (84 loc) · 1.95 KB
/
queue.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
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
104
105
106
107
#include<bits/stdc++.h>
using namespace std;
class Queue {
public:
int front,rear,size;
int capacity;
int* arr;
};
// Queue* createQueue(int capacity){
// Queue queue=new Queue() ;
// queue->front=0;
// queue->rear=-1;
// queue->arr[capacity];
// queue->size=0;
// return queue;
// }
bool isempty(Queue* queue){
if(queue->rear==-1)
return true;
}
bool isFull(Queue* queue){
if(queue->rear ==queue->size){
return true;
}
}
// for adding in the Queue
int enqueue1(Queue* queue ,int numb ){
if(isFull(queue)){
return -1;
}
else{
queue->rear=queue->rear+1;
queue->arr[queue->rear]=numb;
cout<<"Person Inserted in the queue"<<endl;
}
}
int deque1(Queue* queue) {
if(isempty(queue)){
cout<<"No one is in the queue";
}
queue->front=queue->front + 1;
return (queue->arr[queue->front]);
}
int main(){
int i;
int token=0;
//Queue* queue =createQueue(5);
Queue* queue=new Queue() ;
queue->front=0;
queue->rear=-1;
queue->arr[5];
queue->size=0;
while(1){
cout<<"Enetr 1 for going in the queue"<<endl;
cout<<"Enter 2 to serving a person"<<endl;
cout<<"Enter 0 for exit to the Loop"<<endl;
cin>>i;
switch(i){
case 1:
{
token++;
enqueue1(queue,token);
for(int j= 0;j<5;j++){
cout<<queue->arr[j];
}
break;
}
case 2:{
int serving_person =deque1(queue);
for(int j= 0;j<5;j++){
cout<<queue->arr[j];
}
break;
}
default:{
for(int j= 0;j<5;j++){
cout<<queue->arr[j];
}
exit(0);
}
}
}
return 0;
}