ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SequenceStack.h File Reference

SequenceStack is the STACK [see ADT.h] simulated with the operations of any SEQUENCE, the top being its first item: More...

#include "ADS/ADT.h"
#include "ADS/Contract.h"
#include <ranges>
#include "ADS/stack/impl/SequenceStack.tpp"

Go to the source code of this file.

Classes

class  ADS::SequenceStack< S >
 a STACK simulated with the operations of a SEQUENCE S, the top first More...

Namespaces

namespace  ADS

Detailed description

SequenceStack is the STACK [see ADT.h] simulated with the operations of any SEQUENCE, the top being its first item:

\[ \mathrm{top}() = \mathrm{read}( \mathrm{head}() ) \qquad \mathrm{pop}() = \mathrm{remove}( \mathrm{head}() ) \qquad \mathrm{push}( v ) = \mathrm{insert}( \mathrm{head}() , v ) \; , \]

which takes \( O( 1 ) \) time on a list with pointers, even a singly linked one (exercise 4.6), and has no capacity.

The contracts [see Contract.h]: top() and pop() need a stack that is not empty, and push() ensures one that is not. The operations are defined in SequenceStack.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 4.3.1, https://algoritmicamente.it/materiali/libro/capitoli/cap04.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa