-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.cpp
59 lines (43 loc) · 915 Bytes
/
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
//
// AUTHOR: Cole Walgren
// TITLE: Program 3
// DESCRIPTION: Handles all methods relating to the Queue
//
#include <iostream>
#include <string>
#include <cstdlib>
#include "Queue.hpp"
#include "LLN.hpp"
#include "QObj.hpp"
using namespace std;
Queue::Queue () {
// Each Queue has a head
head = nullptr;
}
Queue::~Queue () {
//destructor method
delete head;
}
void Queue::ENQUEUE (QObj *obj) {
// Enqueues "obj" into the Queue
if (!head) head = tail = new LLN (obj);
else {
tail->setnext (new LLN (obj));
tail = tail->getnext();
}
}
QObj * Queue::DEQUEUE () {
// Dequeues an item from the Queue
if (!head) return nullptr;
QObj * obj = head->getinfo ();
LLN *t = head;
head = head->getnext();
t->setnext (nullptr);
t->setinfo (nullptr);
delete t;
return obj;
}
bool Queue::EMPTY () {
//returns true if the Queue is empty
return !head;
}