-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue-wrapper.cpp
80 lines (72 loc) · 1.96 KB
/
queue-wrapper.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "queue-wrapper.h"
using namespace std;
QueueWrapper::QueueWrapper(
const QueueType queueType
): m_queueType(queueType),
m_queue(0),
m_circularQueue(0),
m_doubleStackQueue(0) {
switch(m_queueType) {
case QueueType_DoubleEnded:
m_queue = new std::queue<QueueItem>();
break;
case QueueType_CircularArray:
m_circularQueue = new CircularQueue();
break;
case QueueType_DoubleStacks:
m_doubleStackQueue = new DoubleStackedQueue();
break;
}
}
QueueWrapper::~QueueWrapper() {
if(m_queue != 0) {
delete m_queue;
}
if(m_circularQueue != 0) {
delete m_circularQueue;
}
if(m_doubleStackQueue != 0) {
delete m_doubleStackQueue;
}
}
bool QueueWrapper::empty()const {
switch(m_queueType) {
case QueueType_DoubleEnded:
return m_queue->empty();
case QueueType_CircularArray:
return m_circularQueue->empty();
case QueueType_DoubleStacks:
return m_doubleStackQueue->empty();
}
}
void QueueWrapper::enQueue(const QueueItem & item) {
switch(m_queueType) {
case QueueType_DoubleEnded:
m_queue->push(item);
break;
case QueueType_CircularArray:
m_circularQueue->enQueue(item);
break;
case QueueType_DoubleStacks:
m_doubleStackQueue->enQueue(item);
break;
}
}
void QueueWrapper::deQueue(QueueItem & rItem) {
switch(m_queueType) {
case QueueType_DoubleEnded: {
QueueItem & item = m_queue->front();
rItem = item;
m_queue->pop();
break;
}
case QueueType_CircularArray: {
m_circularQueue->deQueue(rItem);
break;
}
case QueueType_DoubleStacks: {
m_doubleStackQueue->deQueue(rItem);
break;
}
}
}