A dead stupid stack implementation, but one fully working :)
A High-performance, Array-based Stack implementation providing efficient LIFO (Last In, First Out) operations with dynamic growth and proper bounds checking.
A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle. Elements are added and removed from the same end, called the “top” of the stack. Think of it like a stack of plates - you can only add or remove plates from the top.
The following script installs Containers-Stack in Pharo.
Metacello new
baseline: 'ContainersStack';
repository: 'github://pharo-containers/Containers-Stack/src';
load.
Add the following code to your Metacello baseline or configuration
spec
baseline: 'ContainersStack'
with: [ spec repository: 'github://pharo-containers/Containers-Stack/src' ].
"Create a stack (grows automatically when needed)"
stack := CTStack new: 2.
stack capacity. "Returns 2"
"Push elements - grows beyond initial capacity"
stack push: 'first'; push: 'second'; push: 'third'.
stack capacity. "Returns 4 (doubled automatically)"
stack size. "Returns 3"
"LIFO operations"
stack top. "Returns 'third'"
stack pop. "Returns 'third'"
stack pop. "Returns 'second'"
stack pop. "Returns 'first'"
"Stack is now empty"
stack isEmpty. "Returns true"
This is part of the Pharo Containers project. Feel free to contribute by implementing additional methods, improving tests, or enhancing documentation.