@supuwoerc/toolkit
    Preparing search index...

    Class DoublyLinkedList<V>

    双向链表实现 Doubly Linked List Implementation

    Type Parameters

    • V

      链表元素类型 / Type of list elements

    Index

    Constructors

    Accessors

    • get isEmpty(): boolean

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

      Returns boolean

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

    • get size(): number

      获取链表长度 Get the size of the list

      Returns number

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

    Methods

    • 默认迭代器,支持 for...of 循环 Default iterator, supports for...of loop

      Returns Generator<V, void, unknown>

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

      for (const value of list) {
      console.log(value)
      }
    • 获取链表最后一个元素的值 Get the value of the last element

      Returns V | undefined

      最后一个元素的值或 undefined / Value of last element or undefined

    • 清空链表 Clear the list

      Returns void

      移除所有节点,重置链表状态 Remove all nodes and reset list state

    • 清空并遍历链表 Drain and traverse the list

      Returns Generator<V, void, unknown>

      每次移除的链表头部元素值 / Head element value removed each time

      遍历过程中会清空链表 The list will be cleared during traversal

      for (const value of list.drain()) {
      console.log(value) // 链表逐渐被清空 / List is gradually cleared
      }
    • 获取链表第一个元素的值 Get the value of the first element

      Returns V | undefined

      第一个元素的值或 undefined / Value of first element or undefined

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

      Parameters

      • index: number

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

      Returns V | undefined

      索引位置的元素值或 undefined / Element value at index or undefined

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

      Parameters

      • index: number

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

      • value: V

        要插入的值 / Value to insert

      Returns boolean

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

      支持在头部、尾部和中间位置插入 Supports insertion at head, tail, and middle positions

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

      Returns V | undefined

      被移除的元素值或 undefined / Removed element value or undefined

    • 在链表尾部添加元素 Add element at the end of the list

      Parameters

      • value: V

        要添加的值 / Value to add

      Returns this

      链表自身(支持链式调用) / The list itself (supports method chaining)

      list.push(1).push(2).push(3)
      
    • 移除指定索引位置的元素 Remove element at specified index

      Parameters

      • index: number

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

      Returns boolean

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

      支持移除头部、尾部和中间位置的元素 Supports removal of elements at head, tail, and middle positions

    • 从双向链表中移除指定的节点 Removes a specific node from the doubly linked list

      Parameters

      Returns boolean

      如果节点被找到并移除返回 true,否则返回 false / True if the node was found and removed, false otherwise

    • Removes and returns the tail node of the doubly linked list. If the list is empty, returns undefined.

      移除并返回双向链表的尾节点。 如果链表为空,返回 undefined。

      Returns DoublyLinkedListNode<V> | undefined

      The removed tail node, or undefined if the list is empty. 被移除的尾节点,如果链表为空则返回 undefined。

    • 反转链表 Reverse the list

      Returns this

      反转后的链表自身(支持链式调用) / The reversed list itself (supports method chaining)

      原地反转,不创建新链表 In-place reversal, does not create new list

      list.push(1).push(2).push(3)  // 1 ⇄ 2 ⇄ 3
      list.reverse() // 3 ⇄ 2 ⇄ 1
    • 设置指定索引位置的元素值 Set element value at specified index

      Parameters

      • index: number

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

      • value: V

        要设置的新值 / New value to set

      Returns boolean

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

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

      Returns V | undefined

      被移除的元素值或 undefined / Removed element value or undefined

    • 在链表头部添加元素 Add element at the beginning of the list

      Parameters

      • value: V

        要添加的值 / Value to add

      Returns DoublyLinkedList<V>

      链表自身(支持链式调用) / The list itself (supports method chaining)

      list.unshift(1).unshift(2).unshift(3)