|
ADS
Algorithms and Data Structures
|
a QUEUE realized as a singly linked list with a front and a back More...
#include <ADS/queue/LinkedQueue.h>
Public types | |
| using | Item = T |
| the type of the items | |
| using | value_type = T |
| the type of the items | |
| using | size_type = std::size_t |
| the type of the sizes | |
| using | difference_type = std::ptrdiff_t |
| the type of the distances | |
| using | reference = const T & |
| a constant reference | |
| using | const_reference = const T & |
| a constant reference | |
| using | iterator = LinkedIterator< Cell , T , &Cell::next , &Cell::value > |
| a constant iterator along the cells | |
| using | const_iterator |
| a constant iterator along the cells | |
Public member functions | |
| LinkedQueue (void)=default | |
| the empty queue | |
| LinkedQueue (const LinkedQueue &other) | |
| a copy of other, cell by cell | |
| LinkedQueue (LinkedQueue &&other) noexcept | |
| the cells of other, which is left empty | |
| LinkedQueue & | operator= (LinkedQueue other) noexcept |
| the items of other, by copy and swap | |
| ~LinkedQueue () | |
| frees the cells | |
| void | swap (LinkedQueue &other) noexcept |
| exchanges the cells with other | |
| bool | empty (void) const |
| true if there is no item | |
| void | enqueue (const T &v) |
| puts \( v \) at the back | |
| T | dequeue (void) |
| removes the item at the front and returns it | |
| const T & | top (void) const |
| the item at the front | |
| std::size_t | size (void) const |
| the number of items, \( O( 1 ) \) | |
| bool | operator== (const LinkedQueue &o) const |
| the same items in the same order | |
| const_iterator | begin (void) const |
| the iterator on the item at the front | |
| const_iterator | end (void) const |
| the iterator past the item at the back, nil | |
| const_iterator | cbegin (void) const |
| as begin() | |
| const_iterator | cend (void) const |
| as end() | |
a QUEUE realized as a singly linked list with a front and a back
| using ADS::LinkedQueue< T >::const_iterator |
a constant iterator along the cells
| using ADS::LinkedQueue< T >::const_reference = const T & |
a constant reference
| using ADS::LinkedQueue< T >::difference_type = std::ptrdiff_t |
the type of the distances
| using ADS::LinkedQueue< T >::Item = T |
the type of the items
| using ADS::LinkedQueue< T >::iterator = LinkedIterator< Cell , T , &Cell::next , &Cell::value > |
a constant iterator along the cells
| using ADS::LinkedQueue< T >::reference = const T & |
a constant reference
| using ADS::LinkedQueue< T >::size_type = std::size_t |
the type of the sizes
| using ADS::LinkedQueue< T >::value_type = T |
the type of the items
|
default |
the empty queue
| ADS::LinkedQueue< T >::LinkedQueue | ( | const LinkedQueue< T > & | other | ) |
a copy of other, cell by cell
|
noexcept |
the cells of other, which is left empty
| ADS::LinkedQueue< T >::~LinkedQueue | ( | ) |
frees the cells
|
inlinenodiscard |
the iterator on the item at the front
|
inlinenodiscard |
as begin()
|
inlinenodiscard |
as end()
| T ADS::LinkedQueue< T >::dequeue | ( | void | ) |
removes the item at the front and returns it
In pseudocode (exercise 4.10), the first cell unlinked:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{dequeue}() \cr 2 & \quad t \gets \mathit{front};\ v \gets t.\mathit{value}; \ \mathit{front} \gets t.\mathit{next} \cr 3 & \quad \textbf{if}\ \mathit{front} = \textbf{nil}\ \textbf{then} \ \mathit{back} \gets \textbf{nil}\quad \triangleright\ t \text{ was the only cell} \cr 4 & \quad \text{free the cell } t;\ \textbf{return}\ v \end{array}} \]
|
nodiscard |
true if there is no item
|
inlinenodiscard |
the iterator past the item at the back, nil
| void ADS::LinkedQueue< T >::enqueue | ( | const T & | v | ) |
puts \( v \) at the back
In pseudocode (exercise 4.10), a new cell after the last one:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{enqueue}( v ) \cr 2 & \quad t \gets \text{a new cell of value } v \text{ and no successor} \cr 3 & \quad \textbf{if}\ \mathit{back} \ne \textbf{nil}\ \textbf{then} \ \mathit{back}.\mathit{next} \gets t\ \textbf{else}\ \mathit{front} \gets t\quad \triangleright\ \text{an empty queue} \cr 4 & \quad \mathit{back} \gets t \end{array}} \]
|
noexcept |
the items of other, by copy and swap
|
nodiscard |
the same items in the same order
|
nodiscard |
the number of items, \( O( 1 ) \)
|
noexcept |
exchanges the cells with other
|
nodiscard |
the item at the front