Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Stack<T>

Stack implementation based on a linked list. Its elements are managed by two methods push and pop. It implements the CappedStructure interface to handle overflow of a capacity is set.

Type parameters

  • T

Hierarchy

  • Stack

Implements

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Stack(capacity?: undefined | number): Stack
  • Constructor takes an optional capacity parameter. If set, the Stack won't accept new elements after the lengths reache the capacity, until an element is removed.

    Parameters

    • Optional capacity: undefined | number

      The maximum queue length before overflow.

    Returns Stack

Properties

Private Optional _front

_front: StackNode<T>

capacity

capacity: number = -1

The maximum elements the structure can contain. It can be set via the constructor or setCapacity. Default value is -1 (no limit).

length

length: number = 0

The current amount of elements.

Methods

pike

  • Returns the stack's top element without popping it.

    Returns undefined | StackNode<T>

pop

  • pop(): T | undefined
  • Removes the first element and returns its value or undefined if it failed (empty stack).

    Returns T | undefined

    The value of the removed element or undefined if it failed.

push

  • push(value: T): number
  • Adds an element to the front of the stack and returns its length. If the length already reached the (optional) capacity, push is not performed and returns -1.

    Parameters

    • value: T

      The value associed to the pushed element.

    Returns number

    The length of the current Queue after insertion, or -1 if it failed.

Generated using TypeDoc