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

a STACK simulated with the operations of a SEQUENCE S, the top first More...

#include <ADS/stack/SequenceStack.h>

Public types

using Item = typename S::Item
 the type of the items

Public member functions

bool empty (void) const
 true if there is no item, empty() of the sequence
const Item & top (void) const
 the item on top, read( head() )
Item pop (void)
 removes the item on top and returns it, remove( head() )
void push (const Item &v)
 puts \( v \) on top, insert( head() , v )
bool operator== (const SequenceStack &o) const =default
 the same items in the same order, those of the sequences
auto begin (void) const
 the iterator of the sequence on the item on top
auto end (void) const
 the iterator of the sequence past the item at the bottom

Detailed description

template<Sequence S>
class ADS::SequenceStack< S >

a STACK simulated with the operations of a SEQUENCE S, the top first

Member typedef documentation

◆ Item

template<Sequence S>
using ADS::SequenceStack< S >::Item = typename S::Item

the type of the items

Member function documentation

◆ begin()

template<Sequence S>
auto ADS::SequenceStack< S >::begin ( void ) const
inlinenodiscard

the iterator of the sequence on the item on top

◆ empty()

template<Sequence S>
bool ADS::SequenceStack< S >::empty ( void ) const
nodiscard

true if there is no item, empty() of the sequence

◆ end()

template<Sequence S>
auto ADS::SequenceStack< S >::end ( void ) const
inlinenodiscard

the iterator of the sequence past the item at the bottom

◆ operator==()

template<Sequence S>
bool ADS::SequenceStack< S >::operator== ( const SequenceStack< S > & o) const
nodiscarddefault

the same items in the same order, those of the sequences

◆ pop()

template<Sequence S>
Item ADS::SequenceStack< S >::pop ( void )

removes the item on top and returns it, remove( head() )

In pseudocode (section 4.3.1), the item copied before the removal, since a SEQUENCE does not hand out the item it removes:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{pop}() \cr 2 & \quad v \gets S.\mathrm{read}( S.\mathrm{head}() ) \cr 3 & \quad S.\mathrm{remove}( S.\mathrm{head}() ) \cr 4 & \quad \textbf{return}\ v \end{array}} \]

Precondition
the stack is not empty

◆ push()

template<Sequence S>
void ADS::SequenceStack< S >::push ( const Item & v)

puts \( v \) on top, insert( head() , v )

In pseudocode (section 4.3.1):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{push}( v ) \cr 2 & \quad S.\mathrm{insert}( S.\mathrm{head}() , v ) \end{array}} \]

Postcondition
the stack is not empty, \( v \) on top

◆ top()

template<Sequence S>
const Item & ADS::SequenceStack< S >::top ( void ) const
nodiscard

the item on top, read( head() )

In pseudocode (section 4.3.1), \( S \) the sequence:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{top}() \cr 2 & \quad \textbf{return}\ S.\mathrm{read}( S.\mathrm{head}() ) \end{array}} \]

Precondition
the stack is not empty

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