-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.h
More file actions
122 lines (99 loc) · 2.92 KB
/
Queue.h
File metadata and controls
122 lines (99 loc) · 2.92 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// -*- C++ -*-
//==============================================================================
/**
* @file Queue.h
*
* Honor Pledge:
*
* I pledge that I have neither given nor received any help
* on this assignment.
*/
//==============================================================================
#ifndef _QUEUE_H_
#define _QUEUE_H_
#include "Array.h"
#include <exception> // for empty-exception
/**
* @class Queue
*
* Basic queue for abitrary elements.
*/
template <typename T>
class Queue
{
public:
typedef T type;
/**
* @class empty_exception
*
* Exception thrown to indicate the Queue is empty.
*/
class empty_exception : public std::exception
{
public:
/// Default constructor.
empty_exception (void)
: std::exception () { }
/**
* Initializing constructor.
*
* @param[in] msg Error message.
*/
//empty_exception (const char * msg)
//: std::exception (msg) { }
const char * what () const throw ()
{
return "empty_exception: The queue is empty.";
} // end what()
};
/// Default constructor
Queue (void);
/// Copy constructor
Queue (const Queue & queue);
/// Destructor
~Queue (void);
/**
* Assignment operator
*
* @param[in] rhs Right-hand side of operator
* @return Reference to self
*/
const Queue & operator = (const Queue & rhs);
/**
* Add an element to the end of the list
*
* @param[in] element Element to add to the list
*/
void enqueue (T element);
/**
* Remove the element at the front of the list
*
* @return Element at the front of the list
* @exception empty_exception The queue 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 elements on the queue.
*
* @return Size of the queue.
*/
size_t size (void) const;
/// Remove all elements from the stack.
void clear (void);
private:
// COMMENT There is no need to allocate the array on the heap. Always try to
// allocate on the stack to reduce the complexity of your code.
// SOLUTION Dr. Hill, I resolved this comment by allocating the array on the stack.
// aggregation
Array <T> array_;
};
#include "Queue.inl"
#include "Queue.cpp"
#endif // !defined _QUEUE_H_