|
ADS
Algorithms and Data Structures
|
The STACK of the book [see ADT.h] realized with a vector of a given capacity \( c \): the \( n \) items are in the first \( n \) places, the top in the place \( n - 1 \), so that every operation takes \( O( 1 ) \) time. More...
#include "ADS/Contract.h"#include <cstddef>#include <memory>#include <utility>#include "ADS/stack/impl/ArrayStack.tpp"Go to the source code of this file.
Classes | |
| class | ADS::ArrayStack< T > |
| a STACK realized with a vector of a given capacity More... | |
Namespaces | |
| namespace | ADS |
The STACK of the book [see ADT.h] realized with a vector of a given capacity \( c \): the \( n \) items are in the first \( n \) places, the top in the place \( n - 1 \), so that every operation takes \( O( 1 ) \) time.
The contracts [see Contract.h] are the preconditions of the book: top() and pop() need a stack that is not empty (\( n > 0 \)), push() one that is not full (\( n < c \)); push() ensures one item more and \( v \) on top, pop() one item less and the old top returned, which is the constructive form of the axioms \( \mathrm{top}( \mathrm{push}( S , v ) ) = v \) and \( \mathrm{pop}( \mathrm{push}( S , v ) ) = S \) [see ADT.h]. The invariant is \( 0 \leq n \leq c \). A stack is copied item by item and moved in \( O( 1 ) \) time, and two stacks are equal if they hold the same items in the same order, whatever their capacities. The operations are defined in ArrayStack.tpp.