Class Stack<T>

A Stack is a LIFO (last in, first out) ordered list abstract data type. Items can be added to the list, but only at the end (or “top”), and items can be removed from the list, but also only from the end. Thus when removing items, the first item removed is the last item added. The order of items stored in the list is the order they were inserted.

Typeparam

T the type of items in this Stack

Type Parameters

  • T

Constructors

Properties

Accessors

Methods

Constructors

Properties

array: T[] = []

Internal implemenation of this Stack’s data.

Accessors

  • get isEmpty(): boolean
  • Is this Stack empty?

    Returns boolean

    true if this Stack contains no items

Methods

  • Look at the end (the “top”) of this Stack without modifying it.

    Returns T

    the item at the end of this Stack

    Throws

    if this Stack is empty

  • Remove the last item of this Stack, and return a tuple of both.

    Returns [Stack<T>, T]

    a tuple of 2 items: (1) this Stack, minus the popped item, and (2) the popped item

    Throws

    if this Stack is empty

  • Add an item to this Stack.

    Parameters

    • item: T

      the item to push

    Returns this

    this