ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::LinkedQueue< T > Class Template Reference

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()

Detailed description

template<class T>
class ADS::LinkedQueue< T >

a QUEUE realized as a singly linked list with a front and a back

Member typedef documentation

◆ const_iterator

template<class T>
using ADS::LinkedQueue< T >::const_iterator
Initial value:
LinkedIterator< Cell , T , &Cell::next ,
&Cell::value >
a forward iterator along the cells C linked by the member Next, on the items V in the member Value; n...
Definition Iterators.h:132

a constant iterator along the cells

◆ const_reference

template<class T>
using ADS::LinkedQueue< T >::const_reference = const T &

a constant reference

◆ difference_type

template<class T>
using ADS::LinkedQueue< T >::difference_type = std::ptrdiff_t

the type of the distances

◆ Item

template<class T>
using ADS::LinkedQueue< T >::Item = T

the type of the items

◆ iterator

template<class T>
using ADS::LinkedQueue< T >::iterator = LinkedIterator< Cell , T , &Cell::next , &Cell::value >

a constant iterator along the cells

◆ reference

template<class T>
using ADS::LinkedQueue< T >::reference = const T &

a constant reference

◆ size_type

template<class T>
using ADS::LinkedQueue< T >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T>
using ADS::LinkedQueue< T >::value_type = T

the type of the items

Constructor and destructor documentation

◆ LinkedQueue() [1/3]

template<class T>
ADS::LinkedQueue< T >::LinkedQueue ( void )
default

the empty queue

◆ LinkedQueue() [2/3]

template<class T>
ADS::LinkedQueue< T >::LinkedQueue ( const LinkedQueue< T > & other)

a copy of other, cell by cell

◆ LinkedQueue() [3/3]

template<class T>
ADS::LinkedQueue< T >::LinkedQueue ( LinkedQueue< T > && other)
noexcept

the cells of other, which is left empty

◆ ~LinkedQueue()

template<class T>
ADS::LinkedQueue< T >::~LinkedQueue ( )

frees the cells

Member function documentation

◆ begin()

template<class T>
const_iterator ADS::LinkedQueue< T >::begin ( void ) const
inlinenodiscard

the iterator on the item at the front

◆ cbegin()

template<class T>
const_iterator ADS::LinkedQueue< T >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<class T>
const_iterator ADS::LinkedQueue< T >::cend ( void ) const
inlinenodiscard

as end()

◆ dequeue()

template<class T>
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}} \]

Precondition
the queue is not empty

◆ empty()

template<class T>
bool ADS::LinkedQueue< T >::empty ( void ) const
nodiscard

true if there is no item

◆ end()

template<class T>
const_iterator ADS::LinkedQueue< T >::end ( void ) const
inlinenodiscard

the iterator past the item at the back, nil

◆ enqueue()

template<class T>
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}} \]

Postcondition
the queue is not empty, and \( v \) is at the front if it was empty

◆ operator=()

template<class T>
LinkedQueue & ADS::LinkedQueue< T >::operator= ( LinkedQueue< T > other)
noexcept

the items of other, by copy and swap

◆ operator==()

template<class T>
bool ADS::LinkedQueue< T >::operator== ( const LinkedQueue< T > & o) const
nodiscard

the same items in the same order

◆ size()

template<class T>
std::size_t ADS::LinkedQueue< T >::size ( void ) const
nodiscard

the number of items, \( O( 1 ) \)

◆ swap()

template<class T>
void ADS::LinkedQueue< T >::swap ( LinkedQueue< T > & other)
noexcept

exchanges the cells with other

◆ top()

template<class T>
const T & ADS::LinkedQueue< T >::top ( void ) const
nodiscard

the item at the front

Precondition
the queue is not empty

The documentation for this class was generated from the following file: