-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.h
92 lines (79 loc) · 1.78 KB
/
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
// COMMENT You are supposed to use your array class.
#ifndef _CS507_QUEUE_H_
#define _CS507_QUEUE_H_
// include the source file since template class
#include "Array.h"
/**
* @class Queue
*
* Basic queue for abitrary elements.
*/
template <typename T>
class Queue
{
public:
/// Type definition of the type.
typedef T type;
/**
* @class empty_exception
*
* Exception thrown to indicate the queue is empty.
*/
class empty_exception : public std::exception
{
const char* what() const throw()
{
return "Empty queue exception";
}
};
/// Default constructor.
Queue (void);
/// Copy constructor.
Queue (const Queue & s);
/// Destructor.
~Queue (void);
/**
* Assignment operator
*
* @param[in] rhs Right-hand side of operator
* @return Reference to self
*/
const Queue<T> & operator = (const Queue & rhs);
/**
* Adds the element to the end of the queue.
*
* @param[in] element Element to add to the list
*/
void enqueue (T element);
/**
* Removes the element at the from of the list. If there is not elements in
* the queue, this method throws empty_exception.
*
* @exception empty_exception The stack is empty.
*/
T dequeue (void);
/**
* Test if the queue is empty
*
* @retval true The queue is empty
* @retval false The queue is not empty
*/
bool is_empty (void) const;
/**
* Number of element on the queue.
*
* @return Size of the queue.
*/
size_t size (void) const;
/// Remove all elements from the queue.
void clear (void);
private:
// add member variable here
int size_;
int front_;
int back_;
Array<T> data_;
};
#include "Queue.cpp"
#include "Queue.inl"
#endif