ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::Stack Concept Reference

STACK (section 4.3.1): items are added and removed at the top (LIFO). More...

#include <ADS/ADT.h>

Concept definition

template< class S >
concept Stack = requires( S s , const S cs , const typename S::Item & v )
{
typename S::Item;
{ cs.empty() } -> std::same_as< bool >;
s.push( v );
{ s.pop() } -> std::convertible_to< typename S::Item >;
{ cs.top() } -> std::convertible_to< typename S::Item >;
}
STACK (section 4.3.1): items are added and removed at the top (LIFO).
Definition ADT.h:184

Detailed description

STACK (section 4.3.1): items are added and removed at the top (LIFO).

As axioms, \( \mathrm{empty}( \mathrm{create} ) = \mathbf{true} \), \( \mathrm{empty}( \mathrm{push}( S , v ) ) = \mathbf{false} \), \( \mathrm{top}( \mathrm{push}( S , v ) ) = v \), \( \mathrm{pop}( \mathrm{push}( S , v ) ) = S \), while \( \mathrm{top}( \mathrm{create} ) \) and \( \mathrm{pop}( \mathrm{create} ) \) are undefined, i.e., top() and pop() are partial, with the precondition that the stack is not empty; pop() also returns the item it removes, and the axiom is about the stack it leaves [Stack]