-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
49 lines (47 loc) · 938 Bytes
/
Copy pathqueue.cpp
File metadata and controls
49 lines (47 loc) · 938 Bytes
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
#include <cstdlib>
#include "queue.h"
void Customer::set(int arrive) {
this->ptime = std::rand() % 3 + 1;
this->arrive = arrive;
}
Queue::Queue(int s) : size(s) {
this->front = 0;
this->rear = 0;
this->items = 0;
}
Queue::~Queue() {}
bool Queue::empty() const {
return this->items == 0;
}
bool Queue::full() const {
return this->items == this->size;
}
int Queue::get_count() const {
return this->items;
}
bool Queue::enqueue(const Item &item) {
if(this->full())
return false;
Node *add = new Node;
add->item = item;
add->next = 0;
this->items++;
if(this->front == 0) // if the queue is empy
this->front = add;
else
this->rear->next = add;
this->rear = add;
return true;
}
bool Queue::dequeue(Item &item) {
if(this->front == 0)
return false;
item = this->front->item;
this->items--;
Node *temp = this->front;
this->front = this->front->next;
delete temp;
if(this->items == 0)
rear = 0;
return true;
}