-
Notifications
You must be signed in to change notification settings - Fork 1
/
TypedQueue.cpp
63 lines (48 loc) · 913 Bytes
/
TypedQueue.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
60
61
62
#include "TypedQueue.h"
template<typename T>
TypedQueue<T>::TypedQueue() {
m_count = 0;
m_head = NULL;
m_tail = NULL;
}
template<typename T>
TypedQueue<T>::~TypedQueue() {
for (node* n = m_head; n != NULL; m_head = n) {
n = m_head->next;
delete m_head;
}
m_count = 0;
m_tail = NULL;
}
template<typename T>
void TypedQueue<T>::Push(T data) {
node* t = m_tail;
m_tail = (node*) new node;
m_tail->next = NULL;
m_tail->item = data;
if (IsEmpty()) {
m_head = m_tail;
}
else {
t->next = m_tail;
}
m_count++;
}
template<typename T>
T TypedQueue<T>::Pop() {
T data = m_head->item;
node* t = m_head->next;
delete m_head;
m_head = t;
m_count--;
return data;
}
template<typename T>
bool TypedQueue<T>::IsEmpty() {
return m_head == NULL;
}
template<typename T>
int TypedQueue<T>::Count() {
return m_count;
}
template class TypedQueue<String>;