data-structure-typed 1.42.8 → 1.42.9
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 +12 -12
- package/benchmark/report.html +12 -12
- package/benchmark/report.json +106 -106
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/cjs/src/data-structures/binary-tree/bst.js +121 -67
- package/dist/cjs/src/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/cjs/src/data-structures/graph/abstract-graph.js +147 -36
- package/dist/cjs/src/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/cjs/src/data-structures/graph/directed-graph.js +126 -0
- package/dist/cjs/src/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/cjs/src/data-structures/graph/undirected-graph.js +63 -0
- package/dist/cjs/src/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/heap/heap.d.ts +175 -12
- package/dist/cjs/src/data-structures/heap/heap.js +175 -12
- package/dist/cjs/src/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/queue/deque.d.ts +113 -3
- package/dist/cjs/src/data-structures/queue/deque.js +113 -3
- package/dist/cjs/src/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/src/data-structures/queue/queue.d.ts +87 -0
- package/dist/cjs/src/data-structures/queue/queue.js +87 -0
- package/dist/cjs/src/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/src/data-structures/stack/stack.d.ts +42 -0
- package/dist/cjs/src/data-structures/stack/stack.js +42 -0
- package/dist/cjs/src/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/src/data-structures/trie/trie.d.ts +76 -0
- package/dist/cjs/src/data-structures/trie/trie.js +76 -1
- package/dist/cjs/src/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/mjs/src/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/mjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/mjs/src/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/mjs/src/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/mjs/src/data-structures/binary-tree/bst.js +121 -67
- package/dist/mjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/mjs/src/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/mjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/mjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/mjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/mjs/src/data-structures/graph/abstract-graph.js +147 -36
- package/dist/mjs/src/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/mjs/src/data-structures/graph/directed-graph.js +126 -0
- package/dist/mjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/mjs/src/data-structures/graph/undirected-graph.js +63 -0
- package/dist/mjs/src/data-structures/heap/heap.d.ts +175 -12
- package/dist/mjs/src/data-structures/heap/heap.js +175 -12
- package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/mjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/mjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/mjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/mjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/mjs/src/data-structures/queue/deque.d.ts +113 -3
- package/dist/mjs/src/data-structures/queue/deque.js +113 -3
- package/dist/mjs/src/data-structures/queue/queue.d.ts +87 -0
- package/dist/mjs/src/data-structures/queue/queue.js +87 -0
- package/dist/mjs/src/data-structures/stack/stack.d.ts +42 -0
- package/dist/mjs/src/data-structures/stack/stack.js +42 -0
- package/dist/mjs/src/data-structures/trie/trie.d.ts +76 -0
- package/dist/mjs/src/data-structures/trie/trie.js +76 -1
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +97 -23
- package/src/data-structures/binary-tree/binary-tree.ts +419 -204
- package/src/data-structures/binary-tree/bst.ts +130 -68
- package/src/data-structures/binary-tree/rb-tree.ts +106 -19
- package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
- package/src/data-structures/graph/abstract-graph.ts +133 -7
- package/src/data-structures/graph/directed-graph.ts +145 -1
- package/src/data-structures/graph/undirected-graph.ts +72 -0
- package/src/data-structures/heap/heap.ts +201 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
- package/src/data-structures/queue/deque.ts +127 -3
- package/src/data-structures/queue/queue.ts +99 -0
- package/src/data-structures/stack/stack.ts +48 -0
- package/src/data-structures/trie/trie.ts +87 -4
- package/test/integration/index.html +24 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +19 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -1
|
@@ -49,6 +49,13 @@ class DoublyLinkedList {
|
|
|
49
49
|
return this.length;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
+
* Time Complexity: O(n), where n is the length of the input array.
|
|
53
|
+
* Space Complexity: O(n)
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Time Complexity: O(n), where n is the length of the input array.
|
|
57
|
+
* Space Complexity: O(n)
|
|
58
|
+
*
|
|
52
59
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
53
60
|
* given array.
|
|
54
61
|
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
@@ -62,6 +69,13 @@ class DoublyLinkedList {
|
|
|
62
69
|
return doublyLinkedList;
|
|
63
70
|
}
|
|
64
71
|
/**
|
|
72
|
+
* Time Complexity: O(1)
|
|
73
|
+
* Space Complexity: O(1)
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Time Complexity: O(1)
|
|
77
|
+
* Space Complexity: O(1)
|
|
78
|
+
*
|
|
65
79
|
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
66
80
|
* @param {E} value - The value to be added to the linked list.
|
|
67
81
|
*/
|
|
@@ -79,6 +93,13 @@ class DoublyLinkedList {
|
|
|
79
93
|
this._length++;
|
|
80
94
|
}
|
|
81
95
|
/**
|
|
96
|
+
* Time Complexity: O(1)
|
|
97
|
+
* Space Complexity: O(1)
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* Time Complexity: O(1)
|
|
101
|
+
* Space Complexity: O(1)
|
|
102
|
+
*
|
|
82
103
|
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
83
104
|
* @param {E} value - The value to be added to the linked list.
|
|
84
105
|
*/
|
|
@@ -86,6 +107,13 @@ class DoublyLinkedList {
|
|
|
86
107
|
this.push(value);
|
|
87
108
|
}
|
|
88
109
|
/**
|
|
110
|
+
* Time Complexity: O(1)
|
|
111
|
+
* Space Complexity: O(1)
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Time Complexity: O(1)
|
|
115
|
+
* Space Complexity: O(1)
|
|
116
|
+
*
|
|
89
117
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
90
118
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
91
119
|
* list is empty, it returns null.
|
|
@@ -106,6 +134,13 @@ class DoublyLinkedList {
|
|
|
106
134
|
return removedNode.value;
|
|
107
135
|
}
|
|
108
136
|
/**
|
|
137
|
+
* Time Complexity: O(1)
|
|
138
|
+
* Space Complexity: O(1)
|
|
139
|
+
*/
|
|
140
|
+
/**
|
|
141
|
+
* Time Complexity: O(1)
|
|
142
|
+
* Space Complexity: O(1)
|
|
143
|
+
*
|
|
109
144
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
110
145
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
111
146
|
* list is empty, it returns null.
|
|
@@ -114,6 +149,13 @@ class DoublyLinkedList {
|
|
|
114
149
|
return this.pop();
|
|
115
150
|
}
|
|
116
151
|
/**
|
|
152
|
+
* Time Complexity: O(1)
|
|
153
|
+
* Space Complexity: O(1)
|
|
154
|
+
*/
|
|
155
|
+
/**
|
|
156
|
+
* Time Complexity: O(1)
|
|
157
|
+
* Space Complexity: O(1)
|
|
158
|
+
*
|
|
117
159
|
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
118
160
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
119
161
|
* list.
|
|
@@ -134,6 +176,13 @@ class DoublyLinkedList {
|
|
|
134
176
|
return removedNode.value;
|
|
135
177
|
}
|
|
136
178
|
/**
|
|
179
|
+
* Time Complexity: O(1)
|
|
180
|
+
* Space Complexity: O(1)
|
|
181
|
+
*/
|
|
182
|
+
/**
|
|
183
|
+
* Time Complexity: O(1)
|
|
184
|
+
* Space Complexity: O(1)
|
|
185
|
+
*
|
|
137
186
|
* The `popFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
138
187
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
139
188
|
* list.
|
|
@@ -142,6 +191,13 @@ class DoublyLinkedList {
|
|
|
142
191
|
return this.shift();
|
|
143
192
|
}
|
|
144
193
|
/**
|
|
194
|
+
* Time Complexity: O(1)
|
|
195
|
+
* Space Complexity: O(1)
|
|
196
|
+
*/
|
|
197
|
+
/**
|
|
198
|
+
* Time Complexity: O(1)
|
|
199
|
+
* Space Complexity: O(1)
|
|
200
|
+
*
|
|
145
201
|
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
146
202
|
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
147
203
|
* doubly linked list.
|
|
@@ -160,6 +216,13 @@ class DoublyLinkedList {
|
|
|
160
216
|
this._length++;
|
|
161
217
|
}
|
|
162
218
|
/**
|
|
219
|
+
* Time Complexity: O(1)
|
|
220
|
+
* Space Complexity: O(1)
|
|
221
|
+
*/
|
|
222
|
+
/**
|
|
223
|
+
* Time Complexity: O(1)
|
|
224
|
+
* Space Complexity: O(1)
|
|
225
|
+
*
|
|
163
226
|
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
164
227
|
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
165
228
|
* doubly linked list.
|
|
@@ -168,6 +231,13 @@ class DoublyLinkedList {
|
|
|
168
231
|
this.unshift(value);
|
|
169
232
|
}
|
|
170
233
|
/**
|
|
234
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
235
|
+
* Space Complexity: O(1)
|
|
236
|
+
*/
|
|
237
|
+
/**
|
|
238
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
239
|
+
* Space Complexity: O(1)
|
|
240
|
+
*
|
|
171
241
|
* The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
172
242
|
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
173
243
|
*/
|
|
@@ -175,6 +245,13 @@ class DoublyLinkedList {
|
|
|
175
245
|
return this.head?.value;
|
|
176
246
|
}
|
|
177
247
|
/**
|
|
248
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
249
|
+
* Space Complexity: O(1)
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
253
|
+
* Space Complexity: O(1)
|
|
254
|
+
*
|
|
178
255
|
* The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
179
256
|
* @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
180
257
|
*/
|
|
@@ -182,6 +259,13 @@ class DoublyLinkedList {
|
|
|
182
259
|
return this.tail?.value;
|
|
183
260
|
}
|
|
184
261
|
/**
|
|
262
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
263
|
+
* Space Complexity: O(1)
|
|
264
|
+
*/
|
|
265
|
+
/**
|
|
266
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
267
|
+
* Space Complexity: O(1)
|
|
268
|
+
*
|
|
185
269
|
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
186
270
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
187
271
|
* retrieve from the list.
|
|
@@ -198,6 +282,13 @@ class DoublyLinkedList {
|
|
|
198
282
|
return current.value;
|
|
199
283
|
}
|
|
200
284
|
/**
|
|
285
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
286
|
+
* Space Complexity: O(1)
|
|
287
|
+
*/
|
|
288
|
+
/**
|
|
289
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
290
|
+
* Space Complexity: O(1)
|
|
291
|
+
*
|
|
201
292
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
202
293
|
* range.
|
|
203
294
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
@@ -215,6 +306,13 @@ class DoublyLinkedList {
|
|
|
215
306
|
return current;
|
|
216
307
|
}
|
|
217
308
|
/**
|
|
309
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
310
|
+
* Space Complexity: O(1)
|
|
311
|
+
*/
|
|
312
|
+
/**
|
|
313
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
314
|
+
* Space Complexity: O(1)
|
|
315
|
+
*
|
|
218
316
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
219
317
|
* node if found, otherwise it returns null.
|
|
220
318
|
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
@@ -232,6 +330,13 @@ class DoublyLinkedList {
|
|
|
232
330
|
return null;
|
|
233
331
|
}
|
|
234
332
|
/**
|
|
333
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
334
|
+
* Space Complexity: O(1)
|
|
335
|
+
*/
|
|
336
|
+
/**
|
|
337
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
338
|
+
* Space Complexity: O(1)
|
|
339
|
+
*
|
|
235
340
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
236
341
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
237
342
|
* DoublyLinkedList. It is of type number.
|
|
@@ -262,6 +367,13 @@ class DoublyLinkedList {
|
|
|
262
367
|
return true;
|
|
263
368
|
}
|
|
264
369
|
/**
|
|
370
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
371
|
+
* Space Complexity: O(1)
|
|
372
|
+
*/
|
|
373
|
+
/**
|
|
374
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
375
|
+
* Space Complexity: O(1)
|
|
376
|
+
*
|
|
265
377
|
* The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
266
378
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
267
379
|
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
@@ -296,6 +408,13 @@ class DoublyLinkedList {
|
|
|
296
408
|
return false;
|
|
297
409
|
}
|
|
298
410
|
/**
|
|
411
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
412
|
+
* Space Complexity: O(1)
|
|
413
|
+
*/
|
|
414
|
+
/**
|
|
415
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
416
|
+
* Space Complexity: O(1)
|
|
417
|
+
*
|
|
299
418
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
300
419
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
301
420
|
* data structure. It is of type number.
|
|
@@ -318,6 +437,13 @@ class DoublyLinkedList {
|
|
|
318
437
|
return removedNode.value;
|
|
319
438
|
}
|
|
320
439
|
/**
|
|
440
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
441
|
+
* Space Complexity: O(1)
|
|
442
|
+
*/
|
|
443
|
+
/**
|
|
444
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
445
|
+
* Space Complexity: O(1)
|
|
446
|
+
*
|
|
321
447
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
322
448
|
* @param {E | DoublyLinkedListNode<E>} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
|
|
323
449
|
* a `DoublyLinkedListNode<E>` object.
|
|
@@ -351,6 +477,13 @@ class DoublyLinkedList {
|
|
|
351
477
|
return false;
|
|
352
478
|
}
|
|
353
479
|
/**
|
|
480
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
481
|
+
* Space Complexity: O(n)
|
|
482
|
+
*/
|
|
483
|
+
/**
|
|
484
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
485
|
+
* Space Complexity: O(n)
|
|
486
|
+
*
|
|
354
487
|
* The `toArray` function converts a linked list into an array.
|
|
355
488
|
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
356
489
|
*/
|
|
@@ -379,6 +512,13 @@ class DoublyLinkedList {
|
|
|
379
512
|
this._length = 0;
|
|
380
513
|
}
|
|
381
514
|
/**
|
|
515
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
516
|
+
* Space Complexity: O(1)
|
|
517
|
+
*/
|
|
518
|
+
/**
|
|
519
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
520
|
+
* Space Complexity: O(1)
|
|
521
|
+
*
|
|
382
522
|
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
383
523
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
384
524
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
@@ -396,6 +536,13 @@ class DoublyLinkedList {
|
|
|
396
536
|
return null;
|
|
397
537
|
}
|
|
398
538
|
/**
|
|
539
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
540
|
+
* Space Complexity: O(1)
|
|
541
|
+
*/
|
|
542
|
+
/**
|
|
543
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
544
|
+
* Space Complexity: O(1)
|
|
545
|
+
*
|
|
399
546
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
400
547
|
* @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value
|
|
401
548
|
* that we are searching for in the linked list.
|
|
@@ -415,6 +562,13 @@ class DoublyLinkedList {
|
|
|
415
562
|
return -1;
|
|
416
563
|
}
|
|
417
564
|
/**
|
|
565
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
566
|
+
* Space Complexity: O(1)
|
|
567
|
+
*/
|
|
568
|
+
/**
|
|
569
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
570
|
+
* Space Complexity: O(1)
|
|
571
|
+
*
|
|
418
572
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
419
573
|
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
420
574
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
@@ -433,6 +587,13 @@ class DoublyLinkedList {
|
|
|
433
587
|
return null;
|
|
434
588
|
}
|
|
435
589
|
/**
|
|
590
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
591
|
+
* Space Complexity: O(n)
|
|
592
|
+
*/
|
|
593
|
+
/**
|
|
594
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
595
|
+
* Space Complexity: O(n)
|
|
596
|
+
*
|
|
436
597
|
* The `toArrayBackward` function converts a doubly linked list into an array in reverse order.
|
|
437
598
|
* @returns The `toArrayBackward()` function returns an array of type `E[]`.
|
|
438
599
|
*/
|
|
@@ -446,6 +607,13 @@ class DoublyLinkedList {
|
|
|
446
607
|
return array;
|
|
447
608
|
}
|
|
448
609
|
/**
|
|
610
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
611
|
+
* Space Complexity: O(1)
|
|
612
|
+
*/
|
|
613
|
+
/**
|
|
614
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
615
|
+
* Space Complexity: O(1)
|
|
616
|
+
*
|
|
449
617
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
450
618
|
*/
|
|
451
619
|
reverse() {
|
|
@@ -458,6 +626,13 @@ class DoublyLinkedList {
|
|
|
458
626
|
}
|
|
459
627
|
}
|
|
460
628
|
/**
|
|
629
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
630
|
+
* Space Complexity: O(1)
|
|
631
|
+
*/
|
|
632
|
+
/**
|
|
633
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
634
|
+
* Space Complexity: O(1)
|
|
635
|
+
*
|
|
461
636
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
462
637
|
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
463
638
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
@@ -473,6 +648,13 @@ class DoublyLinkedList {
|
|
|
473
648
|
}
|
|
474
649
|
}
|
|
475
650
|
/**
|
|
651
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
652
|
+
* Space Complexity: O(n)
|
|
653
|
+
*/
|
|
654
|
+
/**
|
|
655
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
656
|
+
* Space Complexity: O(n)
|
|
657
|
+
*
|
|
476
658
|
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
|
|
477
659
|
* DoublyLinkedList with the transformed values.
|
|
478
660
|
* @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
|
|
@@ -490,6 +672,13 @@ class DoublyLinkedList {
|
|
|
490
672
|
return mappedList;
|
|
491
673
|
}
|
|
492
674
|
/**
|
|
675
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
676
|
+
* Space Complexity: O(n)
|
|
677
|
+
*/
|
|
678
|
+
/**
|
|
679
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
680
|
+
* Space Complexity: O(n)
|
|
681
|
+
*
|
|
493
682
|
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
|
|
494
683
|
* elements that satisfy the given callback function.
|
|
495
684
|
* @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
|
|
@@ -508,6 +697,13 @@ class DoublyLinkedList {
|
|
|
508
697
|
return filteredList;
|
|
509
698
|
}
|
|
510
699
|
/**
|
|
700
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
701
|
+
* Space Complexity: O(n)
|
|
702
|
+
*/
|
|
703
|
+
/**
|
|
704
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
705
|
+
* Space Complexity: O(n)
|
|
706
|
+
*
|
|
511
707
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
512
708
|
* single value.
|
|
513
709
|
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
@@ -527,6 +723,13 @@ class DoublyLinkedList {
|
|
|
527
723
|
return accumulator;
|
|
528
724
|
}
|
|
529
725
|
/**
|
|
726
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
727
|
+
* Space Complexity: O(1)
|
|
728
|
+
*/
|
|
729
|
+
/**
|
|
730
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
731
|
+
* Space Complexity: O(1)
|
|
732
|
+
*
|
|
530
733
|
* The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
531
734
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
532
735
|
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|