Class Stack<T>

License

MIT

Copyright

Tyler Zeng zrwusa@gmail.com

Type Parameters

  • T = number

Hierarchy

  • Stack

Constructors

  • The constructor initializes an array of elements, which can be provided as an optional parameter.

    Type Parameters

    • T = number

    Parameters

    • Optional elements: T[]

      The elements parameter is an optional parameter of type T[], which represents an array of elements of type T. It is used to initialize the _elements property of the class. If the elements parameter is provided and is an array, it is assigned to the `_elements

    Returns Stack<T>

Properties

_elements: T[]

Methods

  • The clone() function returns a new Stack object with the same elements as the original stack.

    Returns Stack<T>

    The clone() method is returning a new Stack object with a copy of the _elements array.

  • The function checks if an array is empty and returns a boolean value.

    Returns boolean

    A boolean value indicating whether the _elements array is empty or not.

  • The peek function returns the last element of an array, or null if the array is empty.

    Returns null | T

    The peek() function returns the last element of the _elements array, or null if the array is empty.

  • The pop function removes and returns the last element from an array, or returns null if the array is empty.

    Returns null | T

    The pop() method is returning the last element of the array _elements if the array is not empty. If the array is empty, it returns null.

  • The push function adds an element to the stack and returns the updated stack.

    Parameters

    • element: T

      The parameter "element" is of type T, which means it can be any data type.

    Returns Stack<T>

    The push method is returning the updated Stack<T> object.

  • The function "fromArray" creates a new Stack object from an array of elements.

    Type Parameters

    • T

    Parameters

    • elements: T[]

      The elements parameter is an array of elements of type T.

    Returns Stack<T>

    The method is returning a new instance of the Stack class, initialized with the elements from the input array.

Generated using TypeDoc