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

a QUEUE with its least item in \( O( 1 ) \) amortized time More...

#include <ADS/queue/MinQueue.h>

Public types

using Item = T
 the type of the items

Public member functions

 MinQueue (C less=C())
 the empty queue, ordered by less
bool empty (void) const
 true if there is no item
std::size_t size (void) const
 the number \( n \) of items
void enqueue (const T &x)
 \( x \) at the back, on the stack \( I \)
T dequeue (void)
 removes the item at the front and returns it, from the stack \( O \), which takes the items of \( I \) when it is empty
const T & top (void) const
 the item at the front, the top of \( O \) or the bottom of \( I \) if \( O \) is empty
const T & min (void) const
 the least item, the lesser of the minima of the two stacks
void clear (void)
 removes all the items

Detailed description

template<class T, class C = std::less<>>
class ADS::MinQueue< T, C >

a QUEUE with its least item in \( O( 1 ) \) amortized time

Member typedef documentation

◆ Item

template<class T, class C = std::less<>>
using ADS::MinQueue< T, C >::Item = T

the type of the items

Constructor and destructor documentation

◆ MinQueue()

template<class T, class C = std::less<>>
ADS::MinQueue< T, C >::MinQueue ( C less = C())
inlineexplicit

the empty queue, ordered by less

Member function documentation

◆ clear()

template<class T, class C = std::less<>>
void ADS::MinQueue< T, C >::clear ( void )
inline

removes all the items

◆ dequeue()

template<class T, class C = std::less<>>
T ADS::MinQueue< T, C >::dequeue ( void )

removes the item at the front and returns it, from the stack \( O \), which takes the items of \( I \) when it is empty

In pseudocode (Morin, exercise 3.15):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{dequeue}() \cr 2 & \quad \textbf{if}\ O = \emptyset\ \textbf{then}\ \textbf{while} \ I \ne \emptyset\ \textbf{do}\ \mathrm{push}( O , \mathrm{pop}( I ) ) \cr 3 & \quad \textbf{return}\ \mathrm{pop}( O ) \end{array}} \]

Precondition
the queue is not empty
Postcondition
one item less

◆ empty()

template<class T, class C = std::less<>>
bool ADS::MinQueue< T, C >::empty ( void ) const
inlinenodiscard

true if there is no item

◆ enqueue()

template<class T, class C = std::less<>>
void ADS::MinQueue< T, C >::enqueue ( const T & x)

\( x \) at the back, on the stack \( I \)

Postcondition
one item more

◆ min()

template<class T, class C = std::less<>>
const T & ADS::MinQueue< T, C >::min ( void ) const
nodiscard

the least item, the lesser of the minima of the two stacks

Precondition
the queue is not empty

◆ size()

template<class T, class C = std::less<>>
std::size_t ADS::MinQueue< T, C >::size ( void ) const
inlinenodiscard

the number \( n \) of items

◆ top()

template<class T, class C = std::less<>>
const T & ADS::MinQueue< T, C >::top ( void ) const
nodiscard

the item at the front, the top of \( O \) or the bottom of \( I \) if \( O \) is empty

Precondition
the queue is not empty

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