@@ -11,30 +11,46 @@ class queue {
11
11
12
12
public:
13
13
using value_type = ValueType;
14
- /* * Show queue */
14
+ /* *
15
+ * @brief prints the queue into the std::cout
16
+ */
15
17
void display () const {
16
18
std::cout << " Front --> " ;
17
19
display_all (this ->queueFront .get ());
18
20
std::cout << ' \n ' ;
19
21
std::cout << " Size of queue: " << size << ' \n ' ;
20
22
}
21
23
24
+ /* *
25
+ * @brief converts the queue into the std::vector
26
+ * @return std::vector containning all of the elements of the queue in the
27
+ * same order
28
+ */
22
29
std::vector<value_type> toVector () const {
23
30
return push_all_to_vector (this ->queueFront .get (), this ->size );
24
31
}
25
32
26
33
private:
34
+ /* *
35
+ * @brief throws an exception if queue is empty
36
+ * @exception std::invalid_argument if queue is empty
37
+ */
27
38
void ensureNotEmpty () const {
28
39
if (isEmptyQueue ()) {
29
40
throw std::invalid_argument (" Queue is empty." );
30
41
}
31
42
}
32
43
33
44
public:
34
- /* * Determine whether the queue is empty */
45
+ /* *
46
+ * @brief checks if the queue has no elements
47
+ * @return true if the queue is empty, false otherwise
48
+ */
35
49
bool isEmptyQueue () const { return (queueFront == nullptr ); }
36
50
37
- /* * Add new item to the queue */
51
+ /* *
52
+ * @brief inserts a new item into the queue
53
+ */
38
54
void enQueue (const value_type& item) {
39
55
auto newNode = std::make_shared<node_type>();
40
56
newNode->data = item;
@@ -49,20 +65,28 @@ class queue {
49
65
++size;
50
66
}
51
67
52
- /* * Return the first element of the queue */
68
+ /* *
69
+ * @return the first element of the queue
70
+ * @exception std::invalid_argument if queue is empty
71
+ */
53
72
value_type front () const {
54
73
ensureNotEmpty ();
55
74
return queueFront->data ;
56
75
}
57
76
58
- /* * Remove the top element of the queue */
77
+ /* *
78
+ * @brief removes the first element from the queue
79
+ * @exception std::invalid_argument if queue is empty
80
+ */
59
81
void deQueue () {
60
82
ensureNotEmpty ();
61
83
queueFront = queueFront->next ;
62
84
--size;
63
85
}
64
86
65
- /* * Clear queue */
87
+ /* *
88
+ * @brief removes all of the elements of the queue
89
+ */
66
90
void clear () {
67
91
queueFront = nullptr ;
68
92
queueRear = nullptr ;
0 commit comments