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

a STACK realized with a vector of a given capacity More...

#include <ADS/stack/ArrayStack.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 = const T *
 a constant iterator
using const_iterator = const T *
 a constant iterator

Public member functions

 ArrayStack (std::size_t dim)
 the empty stack of at most \( \mathit{dim} \) items
 ArrayStack (const ArrayStack &other)
 a copy of other, item by item
 ArrayStack (ArrayStack &&other) noexcept
 the items of other, which is left empty with no capacity
ArrayStack & operator= (ArrayStack other) noexcept
 the items of other, by copy and swap
void swap (ArrayStack &other) noexcept
 exchanges the items and the capacities with other
bool empty (void) const
 true if there is no item, i.e., \( n = 0 \)
const T & top (void) const
 the item on top, \( A[ n - 1 ] \)
T pop (void)
 removes the item on top and returns it
void push (const T &v)
 puts \( v \) on top
std::size_t size (void) const
 the number of items, \( n \)
std::size_t capacity (void) const
 the maximum number of items, \( c \)
bool operator== (const ArrayStack &o) const
 the same items in the same order, whatever the capacities
const_iterator begin (void) const
 the iterator on the item at the bottom
const_iterator end (void) const
 the iterator past the item on top
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()

Detailed description

template<class T>
class ADS::ArrayStack< T >

a STACK realized with a vector of a given capacity

Member typedef documentation

◆ const_iterator

template<class T>
using ADS::ArrayStack< T >::const_iterator = const T *

a constant iterator

◆ const_reference

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

a constant reference

◆ difference_type

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

the type of the distances

◆ Item

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

the type of the items

◆ iterator

template<class T>
using ADS::ArrayStack< T >::iterator = const T *

a constant iterator

◆ reference

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

a constant reference

◆ size_type

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

the type of the sizes

◆ value_type

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

the type of the items

Constructor and destructor documentation

◆ ArrayStack() [1/3]

template<class T>
ADS::ArrayStack< T >::ArrayStack ( std::size_t dim)
explicit

the empty stack of at most \( \mathit{dim} \) items

◆ ArrayStack() [2/3]

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

a copy of other, item by item

◆ ArrayStack() [3/3]

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

the items of other, which is left empty with no capacity

Member function documentation

◆ begin()

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

the iterator on the item at the bottom

◆ capacity()

template<class T>
std::size_t ADS::ArrayStack< T >::capacity ( void ) const
nodiscard

the maximum number of items, \( c \)

◆ cbegin()

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

as begin()

◆ cend()

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

as end()

◆ empty()

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

true if there is no item, i.e., \( n = 0 \)

◆ end()

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

the iterator past the item on top

◆ operator=()

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

the items of other, by copy and swap

◆ operator==()

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

the same items in the same order, whatever the capacities

◆ pop()

template<class T>
T ADS::ArrayStack< T >::pop ( void )

removes the item on top and returns it

In pseudocode (section 4.3.2), \( A[ 0 .. c - 1 ] \) the vector:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{pop}() \cr 2 & \quad n \gets n - 1 \cr 3 & \quad \textbf{return}\ A[ n ] \end{array}} \]

Precondition
the stack is not empty
Postcondition
one item less, the old top returned

◆ push()

template<class T>
void ADS::ArrayStack< T >::push ( const T & v)

puts \( v \) on top

In pseudocode (section 4.3.2):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{push}( v ) \cr 2 & \quad A[ n ] \gets v;\ n \gets n + 1 \end{array}} \]

Precondition
the stack is not full
Postcondition
one item more, \( v \) on top

◆ size()

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

the number of items, \( n \)

◆ swap()

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

exchanges the items and the capacities with other

◆ top()

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

the item on top, \( A[ n - 1 ] \)

Precondition
the stack is not empty

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