ts-data-forge
    Preparing search index...

    Type Alias Stack<T>

    Stack: Readonly<
        {
            isEmpty: boolean;
            pop: () => Optional<T>;
            push: (value: T) => void;
            size: SizeType.Arr;
        },
    >

    Interface for a high-performance stack with LIFO (Last-In, First-Out) behavior.

    This interface defines a mutable stack data structure where elements are added to and removed from the top, following the Last-In, First-Out principle. The implementation uses a dynamic array for optimal performance, providing O(1) operations for both push and pop operations.

    LIFO Behavior:

    • push: Adds elements to the top of the stack
    • pop: Removes and returns elements from the top of the stack
    • The last element added is the first element to be removed

    Performance Characteristics:

    • Push: O(1) amortized (O(n) when buffer needs resizing)
    • Pop: O(1) always
    • Size/isEmpty: O(1) always
    • Memory efficient with automatic garbage collection of removed elements

    Use Cases:

    • Function call management and recursion
    • Undo/redo functionality
    • Expression evaluation and parsing
    • Depth-first search algorithms
    • Backtracking algorithms
    • Browser history management

    Type Parameters

    • T

      The type of elements stored in the stack.