Interface representing a generic List ADT.

Type Parameters

  • T

Implements

Constructors

Accessors

Methods

  • Adds an element to the end of the list.

    Parameters

    • item: T

      The element to add.

    Returns void

  • Returns true if the list contains the specified element.

    Parameters

    • item: T

      The element to check for.

    Returns boolean

    True if the element is in the list, otherwise false.

  • Iterates over the list and executes the provided function for each element.

    Parameters

    • callback: ((item: T, index: number) => void)

      The function to execute for each element.

        • (item, index): void
        • Parameters

          • item: T
          • index: number

          Returns void

    Returns void

  • Returns the element at a specific position.

    Parameters

    • index: number

      The position of the element to return.

    Returns undefined | T

    The element at the specified position, or undefined if the index is out of bounds.

  • Returns the index of the first occurrence of an element, or -1 if not found.

    Parameters

    • item: T

      The element to search for.

    Returns number

    The index of the element, or -1 if not found.

  • Inserts an element at a specific position in the list.

    Parameters

    • index: number

      The position to insert the element.

    • item: T

      The element to insert.

    Returns void

  • Returns true if the collection is empty.

    Returns boolean

    True if the collection is empty, otherwise false.

  • Removes the first occurrence of an element from the list.

    Parameters

    • item: T

      The element to remove.

    Returns boolean

    True if the element was removed, otherwise false.

  • Removes and returns the element at a specific position.

    Parameters

    • index: number

      The position of the element to remove.

    Returns undefined | T

    The removed element, or undefined if the index is out of bounds.

  • Returns an array representation of the list.

    Returns T[]

    An array containing all the elements in the list.