@supuwoerc/toolkit
    Preparing search index...

    Class LinkedList<T>

    链表类 / Linked List Class 实现一个通用的单向链表数据结构 / Implements a generic linked list data structure

    Type Parameters

    • T

      链表存储的元素类型 / Type of elements stored in the linked list

    Index

    Constructors

    • Type Parameters

      • T

        链表存储的元素类型 / Type of elements stored in the linked list

      Returns LinkedList<T>

    Accessors

    • get isEmpty(): boolean

      检查链表是否为空 / Check if the linked list is empty

      Returns boolean

      如果链表为空返回true,否则返回false / Returns true if the linked list is empty, otherwise false

    • get size(): number

      获取链表的长度 / Get the size of the linked list

      Returns number

      链表中元素的数量 / Number of elements in the linked list

    Methods

    • 迭代器方法,支持for...of循环 / Iterator method, supports for...of loop

      Returns Generator<T, void, unknown>

      链表中的每个元素值 / Each element value in the linked list

    • 获取链表最后一个元素的值 / Get the value of the last element in the linked list

      Returns T | undefined

      如果链表不为空返回最后一个元素的值,否则返回undefined / Returns the value of the last element if list is not empty, otherwise undefined

    • 清空链表并依次产出所有节点值 Empties the linked list and yields all node values in sequence

      Returns Generator<T, void, unknown>

      链表节点的值 - The value of the linked list node

      // 清空链表并处理所有值
      // Empty the list and process all values
      for (const value of list.drain()) {
      console.log(value)
      }
    • 获取链表第一个元素的值 / Get the value of the first element in the linked list

      Returns T | undefined

      如果链表不为空返回第一个元素的值,否则返回undefined / Returns the value of the first element if list is not empty, otherwise undefined

    • 获取指定索引的元素值 / Get the element value at specified index

      Parameters

      • index: number

        要获取的索引位置 / Index position to get

      Returns T | undefined

      如果索引有效返回元素值,否则返回undefined / Returns the element value if index is valid, otherwise undefined

    • 在指定索引位置插入元素 / Insert an element at specified index position

      Parameters

      • index: number

        要插入的索引位置 / Index position to insert

      • value: T

        要插入的值 / Value to insert

      Returns boolean

      如果插入成功返回true,否则返回false / Returns true if inserted successfully, otherwise false

    • 移除并返回链表最后一个元素 / Remove and return the last element of the linked list

      Returns T | undefined

      如果链表不为空返回被移除的元素值,否则返回undefined / Returns the removed element value if list is not empty, otherwise undefined

    • 在链表尾部添加元素 / Add an element to the end of the linked list

      Parameters

      • value: T

        要添加的值 / Value to add

      Returns this

      返回链表实例以支持链式调用 / Returns the linked list instance for method chaining

    • 移除指定索引位置的元素 / Remove the element at specified index position

      Parameters

      • index: number

        要移除的索引位置 / Index position to remove

      Returns boolean

      如果移除成功返回true,否则返回false / Returns true if removed successfully, otherwise false

    • 设置指定索引的元素值 / Set the element value at specified index

      Parameters

      • index: number

        要设置的索引位置 / Index position to set

      • value: T

        要设置的新值 / New value to set

      Returns boolean

      如果设置成功返回true,否则返回false / Returns true if set successfully, otherwise false

    • 移除并返回链表第一个元素 / Remove and return the first element of the linked list

      Returns T | undefined

      如果链表不为空返回被移除的元素值,否则返回undefined / Returns the removed element value if list is not empty, otherwise undefined

    • 在链表头部添加元素 / Add an element to the beginning of the linked list

      Parameters

      • value: T

        要添加的值 / Value to add

      Returns LinkedList<T>

      返回链表实例以支持链式调用 / Returns the linked list instance for method chaining