-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab6_Q2.cpp
More file actions
85 lines (78 loc) · 1.23 KB
/
Lab6_Q2.cpp
File metadata and controls
85 lines (78 loc) · 1.23 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
#include<iostream>
using namespace std;
class queue{
public:
int front;//pop--->front
int rear;//push-->rear
int size;
int *arr;
queue(int s){
size=s;
arr=new int[size];
front=0;
rear=0;
}
void enqueue(int val){
if(!isfull()){
arr[rear]=val;
rear++;
}else{
cout<<"queue is full"<<endl;
}
}
int dequeue(){
int val;
if(front==rear){
cout<<"Empty"<<endl;
return -1;
}else{
val=arr[front];
arr[front]=-1;
front++;
}
if(front==rear){
rear=0;
front=0;
}
return val;
}
bool isempty(){
if(front==rear){
return true;
}
return false;
}
bool isfull(){
if(rear==size){
return true;
}
return false;
}
void display(){
if(isempty()){
cout<<"Empty"<<endl;
return;
}
for(int i=front;i<rear;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
~queue(){
delete[]arr;
}
};
int main(){
queue q1(7);
int custumer_ids[]={13,7,4,1,6,8,10};
int size=sizeof(custumer_ids)/sizeof(custumer_ids[0]);
for(int i=0;i<size;i++){
q1.enqueue(custumer_ids[i]);
}
q1.display();
cout<<"Checkouts"<<endl;
for(int i=0;i<size;i++){
cout<<"Checking out ID:"<<q1.dequeue()<<endl;
}
cout<<"All checked out"<<endl;
}