Interface IStackMutable<V>

Stack (mutable)

stack.push(item); // Add one or more items to the top of the stack
stack.pop(); // Removes and retiurns the item at the top of the stack (ie the newest thing)
stack.peek; // Return what is at the top of the stack or undefined if empty
stack.isEmpty/.isFull;
stack.length; // How many items in stack
stack.data; // Get the underlying array
const sanga = new MutableStack();
sanga.push(`bread`, `tomato`, `cheese`);
sanga.peek; // `cheese`
sanga.pop(); // removes `cheese`
sanga.peek; // `tomato`
sanga.push(`lettuce`, `cheese`); // Stack is now [`bread`, `tomato`, `lettuce`, `cheese`]

Stack can also be created from the basis of an existing array. First index of array will be the bottom of the stack.

interface IStackMutable<V> {
    get data(): readonly V[];
    get isEmpty(): boolean;
    get isFull(): boolean;
    get length(): number;
    get peek(): undefined | V;
    forEach(fn: ((v: V) => void)): void;
    forEachFromTop(fn: ((v: V) => void)): void;
    pop(): undefined | V;
    push(...toAdd: readonly V[]): number;
}

Type Parameters

  • V

    Type of stored items

Hierarchy (view full)

Implemented by

Accessors

  • get data(): readonly V[]
  • Returns readonly V[]

  • get isEmpty(): boolean
  • True if stack is empty

    Returns boolean

  • get isFull(): boolean
  • True if stack is at its capacity. False if not, or if there is no capacity.

    Returns boolean

  • get length(): number
  • Number of items in stack

    Returns number

  • get peek(): undefined | V
  • Get the item at the top of the stack without removing it (like pop would do)

    Returns undefined | V

    Item at the top of the stack, or undefined if empty.

Methods

  • Enumerates stack from bottom-to-top

    Parameters

    • fn: ((v: V) => void)
        • (v): void
        • Parameters

          Returns void

    Returns void

  • Enumerates stack from top-to-bottom

    Parameters

    • fn: ((v: V) => void)
        • (v): void
        • Parameters

          Returns void

    Returns void

  • Remove and return item from the top of the stack, or undefined if empty. If you just want to find out what's at the top, use peek.

    Returns undefined | V

  • Add items to the 'top' of the stack.

    Parameters

    • Rest...toAdd: readonly V[]

      Items to add.

    Returns number

    How many items were added