-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.h
More file actions
81 lines (68 loc) · 1.3 KB
/
queue.h
File metadata and controls
81 lines (68 loc) · 1.3 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
#ifndef queue_h
#define queue_h
#include"List.h"
template<class DATATYPE>
class queue
{
public:
queue();
~queue();
bool isEmpty();
bool enqueue(DATATYPE newData);
DATATYPE dequeue();
void printQueue();
DATATYPE top();
bool clearQueue();
//this uses my List.h and ListNode.h classes that I made. these interface with them
//this is so I can rely on one generalized templated linked list, then I can make tweeks to this
private:
List<DATATYPE>* head;
};
template<class DATATYPE>
queue<DATATYPE>::queue()
{ // new List
head = new List<DATATYPE>();
}
template<class DATATYPE>
queue<DATATYPE>::~queue()
{ //empties list in list.h
head->makeEmpty();
}
template<class DATATYPE>
bool queue<DATATYPE>::isEmpty()
{
return head->isEmpty();
}
template<class DATATYPE>
bool queue<DATATYPE>::enqueue(DATATYPE newData)
{
return head->pushBack(newData);
}
template<class DATATYPE>
DATATYPE queue<DATATYPE>::dequeue()
{
return head->popFront();
}
template<class DATATYPE>
bool queue<DATATYPE>::clearQueue()
{
if(head != NULL)
{
head->makeEmpty(); //deletes all node
head == NULL; //sets points to NULL
return true;
}
else
return false;
}
template<class DATATYPE>
DATATYPE queue<DATATYPE>::top()
{
return head->top();
}
template<class DATATYPE>
void queue<DATATYPE>::printQueue()
{
head->printList();
}
#endif