Interface List<T>

Interface for list data structures.

interface List<T> {
    add(val): void;
    addFirst(val): void;
    addLast(val): void;
    clear(): void;
    contains(val): boolean;
    get(index): T;
    getFirst(): T;
    getLast(): T;
    indexOf(val): number;
    remove(index): void;
    removeFirst(): void;
    removeLast(): void;
    set(index, val): T;
    size(): number;
    toArray(): T[];
}

Type Parameters

  • T

Implemented by

Methods

  • Adds an element to the list (typically at the end).

    Parameters

    • val: T

      The value to add

    Returns void

  • Adds an element to the beginning of the list.

    Parameters

    • val: T

      The value to add

    Returns void

  • Adds an element to the end of the list.

    Parameters

    • val: T

      The value to add

    Returns void

  • Checks if the list contains a specific value.

    Parameters

    • val: T

      The value to search for

    Returns boolean

    True if the value exists in the list, false otherwise

  • Returns the element at the specified index.

    Parameters

    • index: number

      The index of the element to retrieve

    Returns T

    The element at the specified index

    Throws

    Error if the index is out of bounds

  • Returns the first element in the list.

    Returns T

    The first element

    Throws

    Error if the list is empty

  • Returns the last element in the list.

    Returns T

    The last element

    Throws

    Error if the list is empty

  • Returns the index of the first occurrence of the specified value.

    Parameters

    • val: T

      The value to search for

    Returns number

    The index of the value, or -1 if not found

  • Removes the element at the specified index.

    Parameters

    • index: number

      The index of the element to remove

    Returns void

    Throws

    Error if the index is out of bounds

  • Removes the first element from the list.

    Returns void

    Throws

    Error if the list is empty

  • Removes the last element from the list.

    Returns void

    Throws

    Error if the list is empty

  • Replaces the element at the specified index with a new value.

    Parameters

    • index: number

      The index of the element to replace

    • val: T

      The new value

    Returns T

    The previous value at the specified index

    Throws

    Error if the index is out of bounds

  • Returns the number of elements in the list.

    Returns number

    The size of the list

  • Converts the list to an array.

    Returns T[]

    An array containing all elements in the list