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

a double ended queue with its least item in \( O( 1 ) \) amortized time More...

#include <ADS/queue/MinDeque.h>

Public types

using Item = T
 the type of the items

Public member functions

 MinDeque (C less=C())
 the empty deque, 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 push_front (const T &x)
 \( x \) at the front
void push_back (const T &x)
 \( x \) at the back
T pop_front (void)
 removes the item at the front and returns it
T pop_back (void)
 removes the item at the back and returns it, the mirror of pop_front()
const T & front (void) const
 the item at the front
const T & back (void) const
 the item at the back
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::MinDeque< T, C >

a double ended queue with its least item in \( O( 1 ) \) amortized time

Member typedef documentation

◆ Item

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

the type of the items

Constructor and destructor documentation

◆ MinDeque()

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

the empty deque, ordered by less

Member function documentation

◆ back()

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

the item at the back

Precondition
the deque is not empty

◆ clear()

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

removes all the items

◆ empty()

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

true if there is no item

◆ front()

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

the item at the front

Precondition
the deque is not empty

◆ min()

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

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

Precondition
the deque is not empty

◆ pop_back()

template<class T, class C = std::less<>>
T ADS::MinDeque< T, C >::pop_back ( void )

removes the item at the back and returns it, the mirror of pop_front()

Precondition
the deque is not empty
Postcondition
one item less

◆ pop_front()

template<class T, class C = std::less<>>
T ADS::MinDeque< T, C >::pop_front ( void )

removes the item at the front and returns it

In pseudocode (Morin, exercise 3.16), \( F \) and \( B \) the two stacks:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{popFront}() \cr 2 & \quad \textbf{if}\ F = \emptyset\ \textbf{then}\ \mathrm{deal}( B , F ) \cr 3 & \quad \textbf{return}\ \mathrm{pop}( F ) \end{array}} \]

Precondition
the deque is not empty
Postcondition
one item less

◆ push_back()

template<class T, class C = std::less<>>
void ADS::MinDeque< T, C >::push_back ( const T & x)
inline

\( x \) at the back

◆ push_front()

template<class T, class C = std::less<>>
void ADS::MinDeque< T, C >::push_front ( const T & x)
inline

\( x \) at the front

◆ size()

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

the number \( n \) of items


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