Class StackImmutable<V>

Stack (immutable)

stack.push(item); // Return a new stack with item(s) added
stack.pop(); // Return a new stack with top-most item removed (ie. newest)
stack.peek; // Return what is at the top of the stack or undefined if empty
stack.isEmpty;
stack.isFull;
stack.length; // How many items in stack
stack.data; // Get the underlying array
let sanga = new Stack();
sanga = sanga.push(`bread`, `tomato`, `cheese`);
sanga.peek; // `cheese`
sanga = sanga.pop(); // removes `cheese`
sanga.peek; // `tomato`
const sangaAlt = sanga.push(`lettuce`, `cheese`); // sanga stays [`bread`, `tomato`], while sangaAlt is [`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. Stack

Type Parameters

  • V

    Type of stored items

Implements

Constructors

Properties

Accessors

Methods

Constructors

Properties

data: readonly V[]

Accessors

  • 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