-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.h
More file actions
44 lines (31 loc) · 731 Bytes
/
Queue.h
File metadata and controls
44 lines (31 loc) · 731 Bytes
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
#include <exception>
#include <iostream>
#include "LinkedList.h"
using namespace std;
class QueueAccessException : public exception {
virtual const char* what() const throw() {
return "You can not access elements of an empty Queue.";
}
};
template <class DataType>
class Queue {
public:
Queue() {}
void enqueue(const DataType& data) {
list.insertEnd(data);
}
void dequeue() {
list.removeBeginning();
}
DataType front() {
if (isEmpty()) {
throw QueueAccessException();
}
return list.firstNode()->data();
}
bool isEmpty() const {
return list.firstNode() == NULL;
}
private:
LinkedList<DataType> list;
};