-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.cpp
55 lines (47 loc) · 1.09 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
#include "Queue.h"
Queue::Queue() {
front = nullptr;
rear = nullptr;
}
void Queue::enQueue(queueNodeData d) {
queueNode *newNode = new queueNode;
newNode->data = d;
newNode->nextPtr = nullptr;
if (queueIsEmpty()) {
front = newNode;
rear = newNode;
} else {
rear->nextPtr = newNode;
rear = newNode;
}
}
queueNodeData Queue::deQueue() {
queueNodeData tempData;
if (!queueIsEmpty()) {
queueNode *tempNode = front;
front = front->nextPtr;
if (queueIsEmpty()) {
rear = nullptr;
}
delete tempNode;
tempNode = nullptr;
}
return tempData;
}
queueNodeData Queue::peek() {
queueNodeData tempData;
if (!queueIsEmpty()) {
tempData = front->data;
}
return tempData;
}
bool Queue::queueIsEmpty() {
return front == nullptr;
}
void Queue::printQueue() {
queueNode *tempNode = front;
while (tempNode != nullptr) {
cout << tempNode->data.itemCount << " " << tempNode->data.timeAvailable << endl;
tempNode = tempNode->nextPtr;
}
}