Options
All
  • Public
  • Public/Protected
  • All
Menu

The Stack class represents a last-in-first-out (LIFO) stack of generic items. It supports the usual

push and pop operations, along with methods for peeking at the top item. Also it extends

Collection API for iteration and testing whether the Stack is empty.

Type parameters

  • E

Hierarchy

  • Stack

Implemented by

Index

Methods

asCollection

  • Returns collection backed by this stack. Iterations will be in LIFO order. Time complexity is O(1).

    Returns Collection<E>

    collection of elements from this stack.

isEmpty

  • isEmpty(): boolean
  • Returns true if this stack is empty.

    Returns boolean

    true if this stack is empty; false otherwise

peek

  • peek(): E
  • Returns (but does not remove) the item most recently added to this stack.

    throws

    Error('Stack underflow') if this stack is empty

    Returns E

    the element most recently added to this stack.

pop

  • pop(): E
  • Removes and returns the item most recently added to this stack.

    throws

    Error('Stack underflow') if this stack is empty

    Returns E

    the element most recently added.

push

  • push(element: E): Stack<E>
  • Adds the item to this stack.

    Parameters

    • element: E

      the element to add

    Returns Stack<E>

    this stack

size

  • size(): number
  • Returns the number of elements in the stack.

    Returns number

    the number of elements in the stack

toString

  • toString(): string
  • Returns a string representation of this stack.

    Returns string

    the sequence of elements in the stack in LIFO order, separated by spaces

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc