|
ADS
Algorithms and Data Structures
|
\( k \) STACKs in one structure [see ADT.h], beyond the book: the items of all the stacks are cells of a single vector, each linked to the cell below it in its stack, and the free cells form a further list, so that the stacks share the space and none is full while the others have room (the vector, a std::vector, grows by a constant factor when all the cells are used). More...
#include "ADS/Contract.h"#include "ADS/Iterators.h"#include <ranges>#include <utility>#include <vector>#include "ADS/stack/impl/MultiStack.tpp"Go to the source code of this file.
Classes | |
| class | ADS::MultiStack< T > |
| \( k \) stacks sharing a vector of linked cells More... | |
Namespaces | |
| namespace | ADS |
\( k \) STACKs in one structure [see ADT.h], beyond the book: the items of all the stacks are cells of a single vector, each linked to the cell below it in its stack, and the free cells form a further list, so that the stacks share the space and none is full while the others have room (the vector, a std::vector, grows by a constant factor when all the cells are used).
push(), pop() and top() on the stack \( i \) take \( O( 1 ) \) amortized time; the stacks are numbered from 0. It generalizes the two stacks in one vector of exercise 4.7.
The contracts [see Contract.h]: \( k > 0 \), a stack \( i \) in \( [ 0 , k ) \), and a stack that is not empty for top() and pop(); the invariant is that each cell is in exactly one stack or in the free list, and that the sizes count the cells of each stack. The operations are defined in MultiStack.tpp.