|
ADS
Algorithms and Data Structures
|
STACK (section 4.3.1): items are added and removed at the top (LIFO). More...
#include <ADS/ADT.h>
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]