Interface representing a generic Stack ADT.

interface Stack<T> {
    size: number;
    clear(): void;
    isEmpty(): boolean;
    peek(): undefined | T;
    pop(): undefined | T;
    push(item: T): void;
}

Type Parameters

  • T

Hierarchy (view full)

Implemented by

Properties

Methods

Properties

size: number

Gets the number of elements in the collection.

Methods

  • Returns the top element without removing it

    Returns undefined | T

    The top element of stack, or undefined if stack is empty.

  • Removes and returns the top element of the stack

    Returns undefined | T

    The removed element, or undefined if stack is empty.

  • Adds an element to the top of the stack

    Parameters

    • item: T

      The element to add.

    Returns void