data-structure-typed 1.49.0 → 1.49.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +16 -16
- package/README_zh-CN.md +2 -2
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +457 -22
- package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/cjs/data-structures/base/iterable-base.js +21 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/cjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +22 -10
- package/dist/cjs/data-structures/hash/hash-map.js +28 -16
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +20 -38
- package/dist/cjs/data-structures/heap/heap.js +22 -42
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/max-heap.js +10 -7
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/min-heap.js +10 -7
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +132 -136
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -49
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -7
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +76 -80
- package/dist/cjs/data-structures/queue/deque.js +106 -122
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +30 -16
- package/dist/cjs/data-structures/queue/queue.js +31 -24
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +17 -8
- package/dist/cjs/data-structures/stack/stack.js +9 -9
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +14 -5
- package/dist/cjs/data-structures/trie/trie.js +13 -13
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/cjs/types/common.d.ts +32 -8
- package/dist/cjs/types/common.js +22 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/mjs/data-structures/base/iterable-base.js +21 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/mjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/mjs/data-structures/hash/hash-map.d.ts +22 -10
- package/dist/mjs/data-structures/hash/hash-map.js +27 -15
- package/dist/mjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/mjs/data-structures/heap/heap.d.ts +20 -38
- package/dist/mjs/data-structures/heap/heap.js +23 -43
- package/dist/mjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/max-heap.js +9 -6
- package/dist/mjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/min-heap.js +9 -6
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +132 -136
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -50
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +7 -6
- package/dist/mjs/data-structures/queue/deque.d.ts +76 -80
- package/dist/mjs/data-structures/queue/deque.js +106 -122
- package/dist/mjs/data-structures/queue/queue.d.ts +30 -16
- package/dist/mjs/data-structures/queue/queue.js +31 -24
- package/dist/mjs/data-structures/stack/stack.d.ts +17 -8
- package/dist/mjs/data-structures/stack/stack.js +10 -10
- package/dist/mjs/data-structures/trie/trie.d.ts +14 -5
- package/dist/mjs/data-structures/trie/trie.js +14 -14
- package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/mjs/types/common.d.ts +32 -8
- package/dist/mjs/types/common.js +21 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -21
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +533 -558
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +24 -0
- package/src/data-structures/binary-tree/avl-tree.ts +14 -14
- package/src/data-structures/binary-tree/binary-tree.ts +74 -77
- package/src/data-structures/binary-tree/bst.ts +18 -17
- package/src/data-structures/binary-tree/rb-tree.ts +17 -18
- package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
- package/src/data-structures/graph/abstract-graph.ts +35 -25
- package/src/data-structures/graph/directed-graph.ts +2 -2
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +40 -24
- package/src/data-structures/hash/hash-table.ts +3 -3
- package/src/data-structures/heap/heap.ts +33 -60
- package/src/data-structures/heap/max-heap.ts +11 -2
- package/src/data-structures/heap/min-heap.ts +11 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +147 -145
- package/src/data-structures/linked-list/singly-linked-list.ts +52 -52
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +9 -2
- package/src/data-structures/queue/deque.ts +129 -144
- package/src/data-structures/queue/queue.ts +37 -26
- package/src/data-structures/stack/stack.ts +20 -14
- package/src/data-structures/trie/trie.ts +18 -13
- package/src/interfaces/binary-tree.ts +5 -5
- package/src/types/common.ts +37 -12
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
- package/src/types/data-structures/binary-tree/bst.ts +0 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
- package/test/unit/data-structures/graph/directed-graph.test.ts +21 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +39 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +1 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
- package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +5 -5
- package/test/unit/data-structures/queue/queue.test.ts +4 -4
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { IterableElementBase } from
|
|
2
|
-
/**
|
|
3
|
-
* data-structure-typed
|
|
4
|
-
*
|
|
5
|
-
* @author Tyler Zeng
|
|
6
|
-
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
-
* @license MIT License
|
|
8
|
-
*/
|
|
1
|
+
import { IterableElementBase } from '../base';
|
|
9
2
|
export class DoublyLinkedListNode {
|
|
10
3
|
value;
|
|
11
4
|
next;
|
|
@@ -21,15 +14,21 @@ export class DoublyLinkedListNode {
|
|
|
21
14
|
this.prev = undefined;
|
|
22
15
|
}
|
|
23
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
|
|
19
|
+
* 2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
|
|
20
|
+
* 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
|
|
21
|
+
* 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
|
|
22
|
+
*/
|
|
24
23
|
export class DoublyLinkedList extends IterableElementBase {
|
|
25
24
|
/**
|
|
26
|
-
* The constructor initializes the linked list with an empty head, tail, and
|
|
25
|
+
* The constructor initializes the linked list with an empty head, tail, and size.
|
|
27
26
|
*/
|
|
28
27
|
constructor(elements) {
|
|
29
28
|
super();
|
|
30
29
|
this._head = undefined;
|
|
31
30
|
this._tail = undefined;
|
|
32
|
-
this.
|
|
31
|
+
this._size = 0;
|
|
33
32
|
if (elements) {
|
|
34
33
|
for (const el of elements) {
|
|
35
34
|
this.push(el);
|
|
@@ -44,19 +43,16 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
44
43
|
get tail() {
|
|
45
44
|
return this._tail;
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
get length() {
|
|
49
|
-
return this._length;
|
|
50
|
-
}
|
|
46
|
+
_size;
|
|
51
47
|
get size() {
|
|
52
|
-
return this.
|
|
48
|
+
return this._size;
|
|
53
49
|
}
|
|
54
50
|
/**
|
|
55
|
-
* Time Complexity: O(n), where n is the
|
|
51
|
+
* Time Complexity: O(n), where n is the size of the input array.
|
|
56
52
|
* Space Complexity: O(n)
|
|
57
53
|
*/
|
|
58
54
|
/**
|
|
59
|
-
* Time Complexity: O(n), where n is the
|
|
55
|
+
* Time Complexity: O(n), where n is the size of the input array.
|
|
60
56
|
* Space Complexity: O(n)
|
|
61
57
|
*
|
|
62
58
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
@@ -93,21 +89,8 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
93
89
|
this.tail.next = newNode;
|
|
94
90
|
this._tail = newNode;
|
|
95
91
|
}
|
|
96
|
-
this.
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Time Complexity: O(1)
|
|
100
|
-
* Space Complexity: O(1)
|
|
101
|
-
*/
|
|
102
|
-
/**
|
|
103
|
-
* Time Complexity: O(1)
|
|
104
|
-
* Space Complexity: O(1)
|
|
105
|
-
*
|
|
106
|
-
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
107
|
-
* @param {E} value - The value to be added to the linked list.
|
|
108
|
-
*/
|
|
109
|
-
addLast(value) {
|
|
110
|
-
this.push(value);
|
|
92
|
+
this._size++;
|
|
93
|
+
return true;
|
|
111
94
|
}
|
|
112
95
|
/**
|
|
113
96
|
* Time Complexity: O(1)
|
|
@@ -133,24 +116,9 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
133
116
|
this._tail = removedNode.prev;
|
|
134
117
|
this.tail.next = undefined;
|
|
135
118
|
}
|
|
136
|
-
this.
|
|
119
|
+
this._size--;
|
|
137
120
|
return removedNode.value;
|
|
138
121
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Time Complexity: O(1)
|
|
141
|
-
* Space Complexity: O(1)
|
|
142
|
-
*/
|
|
143
|
-
/**
|
|
144
|
-
* Time Complexity: O(1)
|
|
145
|
-
* Space Complexity: O(1)
|
|
146
|
-
*
|
|
147
|
-
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
148
|
-
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
149
|
-
* list is empty, it returns undefined.
|
|
150
|
-
*/
|
|
151
|
-
pollLast() {
|
|
152
|
-
return this.pop();
|
|
153
|
-
}
|
|
154
122
|
/**
|
|
155
123
|
* Time Complexity: O(1)
|
|
156
124
|
* Space Complexity: O(1)
|
|
@@ -175,24 +143,9 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
175
143
|
this._head = removedNode.next;
|
|
176
144
|
this.head.prev = undefined;
|
|
177
145
|
}
|
|
178
|
-
this.
|
|
146
|
+
this._size--;
|
|
179
147
|
return removedNode.value;
|
|
180
148
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Time Complexity: O(1)
|
|
183
|
-
* Space Complexity: O(1)
|
|
184
|
-
*/
|
|
185
|
-
/**
|
|
186
|
-
* Time Complexity: O(1)
|
|
187
|
-
* Space Complexity: O(1)
|
|
188
|
-
*
|
|
189
|
-
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
190
|
-
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
191
|
-
* list.
|
|
192
|
-
*/
|
|
193
|
-
pollFirst() {
|
|
194
|
-
return this.shift();
|
|
195
|
-
}
|
|
196
149
|
/**
|
|
197
150
|
* Time Complexity: O(1)
|
|
198
151
|
* Space Complexity: O(1)
|
|
@@ -216,50 +169,8 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
216
169
|
this.head.prev = newNode;
|
|
217
170
|
this._head = newNode;
|
|
218
171
|
}
|
|
219
|
-
this.
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Time Complexity: O(1)
|
|
223
|
-
* Space Complexity: O(1)
|
|
224
|
-
*/
|
|
225
|
-
/**
|
|
226
|
-
* Time Complexity: O(1)
|
|
227
|
-
* Space Complexity: O(1)
|
|
228
|
-
*
|
|
229
|
-
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
230
|
-
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
231
|
-
* doubly linked list.
|
|
232
|
-
*/
|
|
233
|
-
addFirst(value) {
|
|
234
|
-
this.unshift(value);
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
238
|
-
* Space Complexity: O(1)
|
|
239
|
-
*/
|
|
240
|
-
/**
|
|
241
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
242
|
-
* Space Complexity: O(1)
|
|
243
|
-
*
|
|
244
|
-
* The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
245
|
-
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
246
|
-
*/
|
|
247
|
-
getFirst() {
|
|
248
|
-
return this.head?.value;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
252
|
-
* Space Complexity: O(1)
|
|
253
|
-
*/
|
|
254
|
-
/**
|
|
255
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
256
|
-
* Space Complexity: O(1)
|
|
257
|
-
*
|
|
258
|
-
* The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
259
|
-
* @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
260
|
-
*/
|
|
261
|
-
getLast() {
|
|
262
|
-
return this.tail?.value;
|
|
172
|
+
this._size++;
|
|
173
|
+
return true;
|
|
263
174
|
}
|
|
264
175
|
/**
|
|
265
176
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -276,7 +187,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
276
187
|
* or the linked list is empty, it will return undefined.
|
|
277
188
|
*/
|
|
278
189
|
getAt(index) {
|
|
279
|
-
if (index < 0 || index >= this.
|
|
190
|
+
if (index < 0 || index >= this.size)
|
|
280
191
|
return undefined;
|
|
281
192
|
let current = this.head;
|
|
282
193
|
for (let i = 0; i < index; i++) {
|
|
@@ -300,7 +211,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
300
211
|
* valid range of the linked list, otherwise it returns `undefined`.
|
|
301
212
|
*/
|
|
302
213
|
getNodeAt(index) {
|
|
303
|
-
if (index < 0 || index >= this.
|
|
214
|
+
if (index < 0 || index >= this.size)
|
|
304
215
|
return undefined;
|
|
305
216
|
let current = this.head;
|
|
306
217
|
for (let i = 0; i < index; i++) {
|
|
@@ -348,14 +259,14 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
348
259
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
349
260
|
* if the index is out of bounds.
|
|
350
261
|
*/
|
|
351
|
-
|
|
352
|
-
if (index < 0 || index > this.
|
|
262
|
+
addAt(index, value) {
|
|
263
|
+
if (index < 0 || index > this.size)
|
|
353
264
|
return false;
|
|
354
265
|
if (index === 0) {
|
|
355
266
|
this.unshift(value);
|
|
356
267
|
return true;
|
|
357
268
|
}
|
|
358
|
-
if (index === this.
|
|
269
|
+
if (index === this.size) {
|
|
359
270
|
this.push(value);
|
|
360
271
|
return true;
|
|
361
272
|
}
|
|
@@ -366,7 +277,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
366
277
|
newNode.next = nextNode;
|
|
367
278
|
prevNode.next = newNode;
|
|
368
279
|
nextNode.prev = newNode;
|
|
369
|
-
this.
|
|
280
|
+
this._size++;
|
|
370
281
|
return true;
|
|
371
282
|
}
|
|
372
283
|
/**
|
|
@@ -377,7 +288,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
377
288
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
378
289
|
* Space Complexity: O(1)
|
|
379
290
|
*
|
|
380
|
-
* The `
|
|
291
|
+
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
381
292
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
382
293
|
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
383
294
|
* itself.
|
|
@@ -386,7 +297,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
386
297
|
* @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
387
298
|
* insertion fails.
|
|
388
299
|
*/
|
|
389
|
-
|
|
300
|
+
addBefore(existingValueOrNode, newValue) {
|
|
390
301
|
let existingNode;
|
|
391
302
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
392
303
|
existingNode = existingValueOrNode;
|
|
@@ -405,7 +316,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
405
316
|
if (existingNode === this.head) {
|
|
406
317
|
this._head = newNode;
|
|
407
318
|
}
|
|
408
|
-
this.
|
|
319
|
+
this._size++;
|
|
409
320
|
return true;
|
|
410
321
|
}
|
|
411
322
|
return false;
|
|
@@ -418,7 +329,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
418
329
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
419
330
|
* Space Complexity: O(1)
|
|
420
331
|
*
|
|
421
|
-
* The `
|
|
332
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
422
333
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
423
334
|
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
424
335
|
* itself.
|
|
@@ -426,7 +337,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
426
337
|
* @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
|
|
427
338
|
* existing value or node is not found in the doubly linked list.
|
|
428
339
|
*/
|
|
429
|
-
|
|
340
|
+
addAfter(existingValueOrNode, newValue) {
|
|
430
341
|
let existingNode;
|
|
431
342
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
432
343
|
existingNode = existingValueOrNode;
|
|
@@ -445,7 +356,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
445
356
|
if (existingNode === this.tail) {
|
|
446
357
|
this._tail = newNode;
|
|
447
358
|
}
|
|
448
|
-
this.
|
|
359
|
+
this._size++;
|
|
449
360
|
return true;
|
|
450
361
|
}
|
|
451
362
|
return false;
|
|
@@ -465,19 +376,23 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
465
376
|
* bounds.
|
|
466
377
|
*/
|
|
467
378
|
deleteAt(index) {
|
|
468
|
-
if (index < 0 || index >= this.
|
|
469
|
-
return
|
|
470
|
-
if (index === 0)
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
379
|
+
if (index < 0 || index >= this.size)
|
|
380
|
+
return false;
|
|
381
|
+
if (index === 0) {
|
|
382
|
+
this.shift();
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
if (index === this.size - 1) {
|
|
386
|
+
this.pop();
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
474
389
|
const removedNode = this.getNodeAt(index);
|
|
475
390
|
const prevNode = removedNode.prev;
|
|
476
391
|
const nextNode = removedNode.next;
|
|
477
392
|
prevNode.next = nextNode;
|
|
478
393
|
nextNode.prev = prevNode;
|
|
479
|
-
this.
|
|
480
|
-
return
|
|
394
|
+
this._size--;
|
|
395
|
+
return true;
|
|
481
396
|
}
|
|
482
397
|
/**
|
|
483
398
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -513,26 +428,26 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
513
428
|
const nextNode = node.next;
|
|
514
429
|
prevNode.next = nextNode;
|
|
515
430
|
nextNode.prev = prevNode;
|
|
516
|
-
this.
|
|
431
|
+
this._size--;
|
|
517
432
|
}
|
|
518
433
|
return true;
|
|
519
434
|
}
|
|
520
435
|
return false;
|
|
521
436
|
}
|
|
522
437
|
/**
|
|
523
|
-
* The function checks if a variable has a
|
|
438
|
+
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
524
439
|
* @returns A boolean value is being returned.
|
|
525
440
|
*/
|
|
526
441
|
isEmpty() {
|
|
527
|
-
return this.
|
|
442
|
+
return this.size === 0;
|
|
528
443
|
}
|
|
529
444
|
/**
|
|
530
|
-
* The `clear` function resets the linked list by setting the head, tail, and
|
|
445
|
+
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
531
446
|
*/
|
|
532
447
|
clear() {
|
|
533
448
|
this._head = undefined;
|
|
534
449
|
this._tail = undefined;
|
|
535
|
-
this.
|
|
450
|
+
this._size = 0;
|
|
536
451
|
}
|
|
537
452
|
/**
|
|
538
453
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -627,6 +542,7 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
627
542
|
[current.prev, current.next] = [current.next, current.prev];
|
|
628
543
|
current = next;
|
|
629
544
|
}
|
|
545
|
+
return this;
|
|
630
546
|
}
|
|
631
547
|
/**
|
|
632
548
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -730,12 +646,92 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
730
646
|
}
|
|
731
647
|
return mappedList;
|
|
732
648
|
}
|
|
649
|
+
/**
|
|
650
|
+
* Time Complexity: O(1)
|
|
651
|
+
* Space Complexity: O(1)
|
|
652
|
+
*/
|
|
653
|
+
/**
|
|
654
|
+
* Time Complexity: O(1)
|
|
655
|
+
* Space Complexity: O(1)
|
|
656
|
+
*
|
|
657
|
+
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
658
|
+
* @param {E} value - The value to be added to the linked list.
|
|
659
|
+
*/
|
|
660
|
+
addLast(value) {
|
|
661
|
+
return this.push(value);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Time Complexity: O(1)
|
|
665
|
+
* Space Complexity: O(1)
|
|
666
|
+
*/
|
|
667
|
+
/**
|
|
668
|
+
* Time Complexity: O(1)
|
|
669
|
+
* Space Complexity: O(1)
|
|
670
|
+
*
|
|
671
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
672
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
673
|
+
* list is empty, it returns undefined.
|
|
674
|
+
*/
|
|
675
|
+
pollLast() {
|
|
676
|
+
return this.pop();
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Time Complexity: O(1)
|
|
680
|
+
* Space Complexity: O(1)
|
|
681
|
+
*/
|
|
682
|
+
/**
|
|
683
|
+
* Time Complexity: O(1)
|
|
684
|
+
* Space Complexity: O(1)
|
|
685
|
+
*
|
|
686
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
687
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
688
|
+
* list.
|
|
689
|
+
*/
|
|
690
|
+
pollFirst() {
|
|
691
|
+
return this.shift();
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Time Complexity: O(1)
|
|
695
|
+
* Space Complexity: O(1)
|
|
696
|
+
*/
|
|
697
|
+
/**
|
|
698
|
+
* Time Complexity: O(1)
|
|
699
|
+
* Space Complexity: O(1)
|
|
700
|
+
*
|
|
701
|
+
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
702
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
703
|
+
* doubly linked list.
|
|
704
|
+
*/
|
|
705
|
+
addFirst(value) {
|
|
706
|
+
this.unshift(value);
|
|
707
|
+
}
|
|
733
708
|
/**
|
|
734
709
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
735
|
-
* Space Complexity: O(
|
|
710
|
+
* Space Complexity: O(1)
|
|
736
711
|
*/
|
|
737
|
-
|
|
738
|
-
|
|
712
|
+
/**
|
|
713
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
714
|
+
* Space Complexity: O(1)
|
|
715
|
+
*
|
|
716
|
+
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
717
|
+
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
718
|
+
*/
|
|
719
|
+
get first() {
|
|
720
|
+
return this.head?.value;
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
724
|
+
* Space Complexity: O(1)
|
|
725
|
+
*/
|
|
726
|
+
/**
|
|
727
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
728
|
+
* Space Complexity: O(1)
|
|
729
|
+
*
|
|
730
|
+
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
731
|
+
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
732
|
+
*/
|
|
733
|
+
get last() {
|
|
734
|
+
return this.tail?.value;
|
|
739
735
|
}
|
|
740
736
|
/**
|
|
741
737
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { IterableElementBase } from "../base";
|
|
2
|
-
import { ElementCallback } from "../../types";
|
|
3
1
|
/**
|
|
4
2
|
* data-structure-typed
|
|
5
3
|
*
|
|
@@ -7,6 +5,8 @@ import { ElementCallback } from "../../types";
|
|
|
7
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
8
6
|
* @license MIT License
|
|
9
7
|
*/
|
|
8
|
+
import type { ElementCallback } from "../../types";
|
|
9
|
+
import { IterableElementBase } from "../base";
|
|
10
10
|
export declare class SinglyLinkedListNode<E = any> {
|
|
11
11
|
value: E;
|
|
12
12
|
next: SinglyLinkedListNode<E> | undefined;
|
|
@@ -26,8 +26,8 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
26
26
|
get head(): SinglyLinkedListNode<E> | undefined;
|
|
27
27
|
protected _tail: SinglyLinkedListNode<E> | undefined;
|
|
28
28
|
get tail(): SinglyLinkedListNode<E> | undefined;
|
|
29
|
-
protected
|
|
30
|
-
get
|
|
29
|
+
protected _size: number;
|
|
30
|
+
get size(): number;
|
|
31
31
|
/**
|
|
32
32
|
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
33
33
|
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
|
|
@@ -54,7 +54,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
54
54
|
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
55
55
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
56
56
|
*/
|
|
57
|
-
push(value: E):
|
|
57
|
+
push(value: E): boolean;
|
|
58
58
|
/**
|
|
59
59
|
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
60
60
|
* Space Complexity: O(1) - Constant space, as it only creates a new node.
|
|
@@ -67,7 +67,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
67
67
|
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
68
68
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
69
69
|
*/
|
|
70
|
-
addLast(value: E):
|
|
70
|
+
addLast(value: E): boolean;
|
|
71
71
|
/**
|
|
72
72
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
73
73
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -132,7 +132,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
132
132
|
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
133
133
|
* linked list.
|
|
134
134
|
*/
|
|
135
|
-
unshift(value: E):
|
|
135
|
+
unshift(value: E): boolean;
|
|
136
136
|
/**
|
|
137
137
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
138
138
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -145,7 +145,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
145
145
|
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
146
146
|
* linked list.
|
|
147
147
|
*/
|
|
148
|
-
addFirst(value: E):
|
|
148
|
+
addFirst(value: E): boolean;
|
|
149
149
|
/**
|
|
150
150
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
151
151
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -190,7 +190,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
190
190
|
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
191
191
|
* bounds.
|
|
192
192
|
*/
|
|
193
|
-
deleteAt(index: number):
|
|
193
|
+
deleteAt(index: number): boolean;
|
|
194
194
|
/**
|
|
195
195
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
196
196
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -205,7 +205,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
205
205
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
|
|
206
206
|
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
207
207
|
*/
|
|
208
|
-
delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined
|
|
208
|
+
delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined): boolean;
|
|
209
209
|
/**
|
|
210
210
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
211
211
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -214,7 +214,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
214
214
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
215
215
|
* Space Complexity: O(1) - Constant space.
|
|
216
216
|
*
|
|
217
|
-
* The `
|
|
217
|
+
* The `addAt` function inserts a value at a specified index in a singly linked list.
|
|
218
218
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
219
219
|
* linked list. It is of type number.
|
|
220
220
|
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
@@ -222,7 +222,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
222
222
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
223
223
|
* if the index is out of bounds.
|
|
224
224
|
*/
|
|
225
|
-
|
|
225
|
+
addAt(index: number, value: E): boolean;
|
|
226
226
|
/**
|
|
227
227
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
228
228
|
* whether it is empty or not.
|
|
@@ -256,7 +256,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
256
256
|
* The `reverse` function reverses the order of the nodes in a singly linked list.
|
|
257
257
|
* @returns The reverse() method does not return anything. It has a return type of void.
|
|
258
258
|
*/
|
|
259
|
-
reverse():
|
|
259
|
+
reverse(): this;
|
|
260
260
|
/**
|
|
261
261
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
262
262
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -309,14 +309,14 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
309
309
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
310
310
|
* Space Complexity: O(1) - Constant space.
|
|
311
311
|
*
|
|
312
|
-
* The `
|
|
312
|
+
* The `addBefore` function inserts a new value before an existing value in a singly linked list.
|
|
313
313
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
314
314
|
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
315
315
|
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
316
|
-
* @returns The method `
|
|
316
|
+
* @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
317
317
|
* inserted before the existing value, and `false` otherwise.
|
|
318
318
|
*/
|
|
319
|
-
|
|
319
|
+
addBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
320
320
|
/**
|
|
321
321
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
322
322
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -325,14 +325,14 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
325
325
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
326
326
|
* Space Complexity: O(1) - Constant space.
|
|
327
327
|
*
|
|
328
|
-
* The `
|
|
328
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
|
|
329
329
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
|
|
330
330
|
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
331
331
|
* @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
|
|
332
332
|
* @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
|
|
333
333
|
* existing value or node, and false if the existing value or node was not found in the linked list.
|
|
334
334
|
*/
|
|
335
|
-
|
|
335
|
+
addAfter(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
336
336
|
/**
|
|
337
337
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
338
338
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -387,10 +387,5 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
387
387
|
* of applying the provided `callback` function to each element in the original list.
|
|
388
388
|
*/
|
|
389
389
|
map<T>(callback: ElementCallback<E, T>, thisArg?: any): SinglyLinkedList<T>;
|
|
390
|
-
/**
|
|
391
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
392
|
-
* Space Complexity: O(n)
|
|
393
|
-
*/
|
|
394
|
-
print(): void;
|
|
395
390
|
protected _getIterator(): IterableIterator<E>;
|
|
396
391
|
}
|