项目作者: pharo-containers

项目描述 :
A dead stupid stack implementation, but one fully working :)
高级语言: Smalltalk
项目地址: git://github.com/pharo-containers/Containers-Stack.git
创建时间: 2019-03-14T19:24:53Z
项目社区:https://github.com/pharo-containers/Containers-Stack

开源协议:

下载


Containers-Stack

A High-performance, Array-based Stack implementation providing efficient LIFO (Last In, First Out) operations with dynamic growth and proper bounds checking.

Pharo Version
License: MIT

What is a Stack?

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.

Key Benefits

  • O(1) Performance: Constant time push, pop, and top operations
  • Dynamic Growth: Automatically expands capacity when needed - no size limits
  • Simple API: Clean, intuitive interface following standard conventions
  • Robust Error Handling: Proper stack underflow protection

Loading

The following script installs Containers-Stack in Pharo.

  1. Metacello new
  2. baseline: 'ContainersStack';
  3. repository: 'github://pharo-containers/Containers-Stack/src';
  4. load.

If you want to depend on it

Add the following code to your Metacello baseline or configuration

  1. spec
  2. baseline: 'ContainersStack'
  3. with: [ spec repository: 'github://pharo-containers/Containers-Stack/src' ].

Quick Start

  1. "Create a stack (grows automatically when needed)"
  2. stack := CTStack new: 2.
  3. stack capacity. "Returns 2"
  4. "Push elements - grows beyond initial capacity"
  5. stack push: 'first'; push: 'second'; push: 'third'.
  6. stack capacity. "Returns 4 (doubled automatically)"
  7. stack size. "Returns 3"
  8. "LIFO operations"
  9. stack top. "Returns 'third'"
  10. stack pop. "Returns 'third'"
  11. stack pop. "Returns 'second'"
  12. stack pop. "Returns 'first'"
  13. "Stack is now empty"
  14. stack isEmpty. "Returns true"

Contributing

This is part of the Pharo Containers project. Feel free to contribute by implementing additional methods, improving tests, or enhancing documentation.