Class Stack<T>

A stack data structure.

Type Parameters

  • T

    The type of elements held in the stack.

Hierarchy

  • Stack

Implements

Constructors

Properties

Accessors

Methods

Constructors

  • Creates a new stack with the specified size or elements.

    Type Parameters

    • T

    Parameters

    • size: number | T[]

      The size of the stack or an array of elements to initialize the stack with.

    Returns Stack<T>

Properties

_capacity: number = 0
_data: T[] = []
size: number = 0

The number of elements in the list.

Accessors

  • get hasRoom(): boolean
  • Returns true if the stack has room for more elements, false otherwise.

    Returns boolean

    True if the stack has room for more elements, false otherwise.

Methods

  • Removes and returns the element at the top of the stack.

    Returns undefined | T

    The element at the top of the stack.

    Throws

    An error if the stack is empty.

  • Adds an element to the top of the stack.

    Parameters

    • element: T

      The element to add to the stack.

    Returns void

    Throws

    An error if the stack is full.