-
Notifications
You must be signed in to change notification settings - Fork 1
/
lab_queue.h
99 lines (87 loc) · 1.91 KB
/
lab_queue.h
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef QUEUE_H
#define QUEUE_H
#include <exception>
#include <vector>
using namespace std;
class Queue
{
private:
const int maxSize;
vector<char> queue;
public:
class Full: public exception
{
public:
virtual const char* what() const throw()
{
return "Queue is full";
}
};
class Empty: public exception
{
public:
virtual const char* what() const throw()
{
return "Queue is empty";
}
};
/** Initialise the queue, maxSize is the maximum number of
values that can be stored in the queue at any time **/
Queue( const int _maxSize ) : maxSize(_maxSize)
{
}
~Queue()
{
}
/** Returns the number of values currently stored in the
queue **/
int num_items() const
{
// COMPLETE ME
return 0;
}
/** Add value to the front of the queue, raises Queue::Full
exception is queue is full **/
void push( char value )
{
if( num_items() < maxSize )
{
queue.emplace_back(value);
}
else
{
throw Full();
}
}
/** Returns the value currently stored at the front of the
queue, raises Queue::Empty exception is queue is
empty **/
char front() const
{
if( num_items() > 0 )
{
return queue.front();
}
else
{
throw Empty();
}
}
/** Returns the value currently stored at the back of the
queue, raises Queue.Empty exception if the queue is
empty **/
char back() const
{
// COMPLETE ME
return 0;
}
/** Removes and returns the value currently stored at the
front of the queue, raises Queue::Empty exception is queue
is empty **/
char pop()
{
// COMPLETE ME
return 0;
}
};
#endif