min-heap-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/dist/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/data-structures/binary-tree/bst.js +121 -67
- package/dist/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/data-structures/graph/abstract-graph.js +147 -36
- package/dist/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/data-structures/graph/directed-graph.js +126 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/data-structures/graph/undirected-graph.js +63 -0
- package/dist/data-structures/heap/heap.d.ts +175 -12
- package/dist/data-structures/heap/heap.js +175 -12
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/data-structures/queue/deque.d.ts +113 -3
- package/dist/data-structures/queue/deque.js +113 -3
- package/dist/data-structures/queue/queue.d.ts +87 -0
- package/dist/data-structures/queue/queue.js +87 -0
- package/dist/data-structures/stack/stack.d.ts +42 -0
- package/dist/data-structures/stack/stack.js +42 -0
- package/dist/data-structures/trie/trie.d.ts +76 -0
- package/dist/data-structures/trie/trie.js +76 -1
- package/package.json +2 -2
- 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
|
@@ -43,6 +43,13 @@ class DoublyLinkedList {
|
|
|
43
43
|
return this.length;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
+
* Time Complexity: O(n), where n is the length of the input array.
|
|
47
|
+
* Space Complexity: O(n)
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Time Complexity: O(n), where n is the length of the input array.
|
|
51
|
+
* Space Complexity: O(n)
|
|
52
|
+
*
|
|
46
53
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
47
54
|
* given array.
|
|
48
55
|
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
@@ -56,6 +63,13 @@ class DoublyLinkedList {
|
|
|
56
63
|
return doublyLinkedList;
|
|
57
64
|
}
|
|
58
65
|
/**
|
|
66
|
+
* Time Complexity: O(1)
|
|
67
|
+
* Space Complexity: O(1)
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* Time Complexity: O(1)
|
|
71
|
+
* Space Complexity: O(1)
|
|
72
|
+
*
|
|
59
73
|
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
60
74
|
* @param {E} value - The value to be added to the linked list.
|
|
61
75
|
*/
|
|
@@ -73,6 +87,13 @@ class DoublyLinkedList {
|
|
|
73
87
|
this._length++;
|
|
74
88
|
}
|
|
75
89
|
/**
|
|
90
|
+
* Time Complexity: O(1)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* Time Complexity: O(1)
|
|
95
|
+
* Space Complexity: O(1)
|
|
96
|
+
*
|
|
76
97
|
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
77
98
|
* @param {E} value - The value to be added to the linked list.
|
|
78
99
|
*/
|
|
@@ -80,6 +101,13 @@ class DoublyLinkedList {
|
|
|
80
101
|
this.push(value);
|
|
81
102
|
}
|
|
82
103
|
/**
|
|
104
|
+
* Time Complexity: O(1)
|
|
105
|
+
* Space Complexity: O(1)
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* Time Complexity: O(1)
|
|
109
|
+
* Space Complexity: O(1)
|
|
110
|
+
*
|
|
83
111
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
84
112
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
85
113
|
* list is empty, it returns null.
|
|
@@ -100,6 +128,13 @@ class DoublyLinkedList {
|
|
|
100
128
|
return removedNode.value;
|
|
101
129
|
}
|
|
102
130
|
/**
|
|
131
|
+
* Time Complexity: O(1)
|
|
132
|
+
* Space Complexity: O(1)
|
|
133
|
+
*/
|
|
134
|
+
/**
|
|
135
|
+
* Time Complexity: O(1)
|
|
136
|
+
* Space Complexity: O(1)
|
|
137
|
+
*
|
|
103
138
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
104
139
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
105
140
|
* list is empty, it returns null.
|
|
@@ -108,6 +143,13 @@ class DoublyLinkedList {
|
|
|
108
143
|
return this.pop();
|
|
109
144
|
}
|
|
110
145
|
/**
|
|
146
|
+
* Time Complexity: O(1)
|
|
147
|
+
* Space Complexity: O(1)
|
|
148
|
+
*/
|
|
149
|
+
/**
|
|
150
|
+
* Time Complexity: O(1)
|
|
151
|
+
* Space Complexity: O(1)
|
|
152
|
+
*
|
|
111
153
|
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
112
154
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
113
155
|
* list.
|
|
@@ -128,6 +170,13 @@ class DoublyLinkedList {
|
|
|
128
170
|
return removedNode.value;
|
|
129
171
|
}
|
|
130
172
|
/**
|
|
173
|
+
* Time Complexity: O(1)
|
|
174
|
+
* Space Complexity: O(1)
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Time Complexity: O(1)
|
|
178
|
+
* Space Complexity: O(1)
|
|
179
|
+
*
|
|
131
180
|
* The `popFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
132
181
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
133
182
|
* list.
|
|
@@ -136,6 +185,13 @@ class DoublyLinkedList {
|
|
|
136
185
|
return this.shift();
|
|
137
186
|
}
|
|
138
187
|
/**
|
|
188
|
+
* Time Complexity: O(1)
|
|
189
|
+
* Space Complexity: O(1)
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* Time Complexity: O(1)
|
|
193
|
+
* Space Complexity: O(1)
|
|
194
|
+
*
|
|
139
195
|
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
140
196
|
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
141
197
|
* doubly linked list.
|
|
@@ -154,6 +210,13 @@ class DoublyLinkedList {
|
|
|
154
210
|
this._length++;
|
|
155
211
|
}
|
|
156
212
|
/**
|
|
213
|
+
* Time Complexity: O(1)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* Time Complexity: O(1)
|
|
218
|
+
* Space Complexity: O(1)
|
|
219
|
+
*
|
|
157
220
|
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
158
221
|
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
159
222
|
* doubly linked list.
|
|
@@ -162,6 +225,13 @@ class DoublyLinkedList {
|
|
|
162
225
|
this.unshift(value);
|
|
163
226
|
}
|
|
164
227
|
/**
|
|
228
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
229
|
+
* Space Complexity: O(1)
|
|
230
|
+
*/
|
|
231
|
+
/**
|
|
232
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
233
|
+
* Space Complexity: O(1)
|
|
234
|
+
*
|
|
165
235
|
* The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
166
236
|
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
167
237
|
*/
|
|
@@ -170,6 +240,13 @@ class DoublyLinkedList {
|
|
|
170
240
|
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
171
241
|
}
|
|
172
242
|
/**
|
|
243
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
244
|
+
* Space Complexity: O(1)
|
|
245
|
+
*/
|
|
246
|
+
/**
|
|
247
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
248
|
+
* Space Complexity: O(1)
|
|
249
|
+
*
|
|
173
250
|
* The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
174
251
|
* @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
175
252
|
*/
|
|
@@ -178,6 +255,13 @@ class DoublyLinkedList {
|
|
|
178
255
|
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
|
|
179
256
|
}
|
|
180
257
|
/**
|
|
258
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
259
|
+
* Space Complexity: O(1)
|
|
260
|
+
*/
|
|
261
|
+
/**
|
|
262
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
263
|
+
* Space Complexity: O(1)
|
|
264
|
+
*
|
|
181
265
|
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
182
266
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
183
267
|
* retrieve from the list.
|
|
@@ -194,6 +278,13 @@ class DoublyLinkedList {
|
|
|
194
278
|
return current.value;
|
|
195
279
|
}
|
|
196
280
|
/**
|
|
281
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
282
|
+
* Space Complexity: O(1)
|
|
283
|
+
*/
|
|
284
|
+
/**
|
|
285
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
286
|
+
* Space Complexity: O(1)
|
|
287
|
+
*
|
|
197
288
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
198
289
|
* range.
|
|
199
290
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
@@ -211,6 +302,13 @@ class DoublyLinkedList {
|
|
|
211
302
|
return current;
|
|
212
303
|
}
|
|
213
304
|
/**
|
|
305
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
306
|
+
* Space Complexity: O(1)
|
|
307
|
+
*/
|
|
308
|
+
/**
|
|
309
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
310
|
+
* Space Complexity: O(1)
|
|
311
|
+
*
|
|
214
312
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
215
313
|
* node if found, otherwise it returns null.
|
|
216
314
|
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
@@ -228,6 +326,13 @@ class DoublyLinkedList {
|
|
|
228
326
|
return null;
|
|
229
327
|
}
|
|
230
328
|
/**
|
|
329
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
330
|
+
* Space Complexity: O(1)
|
|
331
|
+
*/
|
|
332
|
+
/**
|
|
333
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
334
|
+
* Space Complexity: O(1)
|
|
335
|
+
*
|
|
231
336
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
232
337
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
233
338
|
* DoublyLinkedList. It is of type number.
|
|
@@ -258,6 +363,13 @@ class DoublyLinkedList {
|
|
|
258
363
|
return true;
|
|
259
364
|
}
|
|
260
365
|
/**
|
|
366
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
367
|
+
* Space Complexity: O(1)
|
|
368
|
+
*/
|
|
369
|
+
/**
|
|
370
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
371
|
+
* Space Complexity: O(1)
|
|
372
|
+
*
|
|
261
373
|
* The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
262
374
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
263
375
|
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
@@ -292,6 +404,13 @@ class DoublyLinkedList {
|
|
|
292
404
|
return false;
|
|
293
405
|
}
|
|
294
406
|
/**
|
|
407
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
408
|
+
* Space Complexity: O(1)
|
|
409
|
+
*/
|
|
410
|
+
/**
|
|
411
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
412
|
+
* Space Complexity: O(1)
|
|
413
|
+
*
|
|
295
414
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
296
415
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
297
416
|
* data structure. It is of type number.
|
|
@@ -314,6 +433,13 @@ class DoublyLinkedList {
|
|
|
314
433
|
return removedNode.value;
|
|
315
434
|
}
|
|
316
435
|
/**
|
|
436
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
437
|
+
* Space Complexity: O(1)
|
|
438
|
+
*/
|
|
439
|
+
/**
|
|
440
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
441
|
+
* Space Complexity: O(1)
|
|
442
|
+
*
|
|
317
443
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
318
444
|
* @param {E | DoublyLinkedListNode<E>} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
|
|
319
445
|
* a `DoublyLinkedListNode<E>` object.
|
|
@@ -347,6 +473,13 @@ class DoublyLinkedList {
|
|
|
347
473
|
return false;
|
|
348
474
|
}
|
|
349
475
|
/**
|
|
476
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
477
|
+
* Space Complexity: O(n)
|
|
478
|
+
*/
|
|
479
|
+
/**
|
|
480
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
481
|
+
* Space Complexity: O(n)
|
|
482
|
+
*
|
|
350
483
|
* The `toArray` function converts a linked list into an array.
|
|
351
484
|
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
352
485
|
*/
|
|
@@ -375,6 +508,13 @@ class DoublyLinkedList {
|
|
|
375
508
|
this._length = 0;
|
|
376
509
|
}
|
|
377
510
|
/**
|
|
511
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
512
|
+
* Space Complexity: O(1)
|
|
513
|
+
*/
|
|
514
|
+
/**
|
|
515
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
516
|
+
* Space Complexity: O(1)
|
|
517
|
+
*
|
|
378
518
|
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
379
519
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
380
520
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
@@ -392,6 +532,13 @@ class DoublyLinkedList {
|
|
|
392
532
|
return null;
|
|
393
533
|
}
|
|
394
534
|
/**
|
|
535
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
536
|
+
* Space Complexity: O(1)
|
|
537
|
+
*/
|
|
538
|
+
/**
|
|
539
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
540
|
+
* Space Complexity: O(1)
|
|
541
|
+
*
|
|
395
542
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
396
543
|
* @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value
|
|
397
544
|
* that we are searching for in the linked list.
|
|
@@ -411,6 +558,13 @@ class DoublyLinkedList {
|
|
|
411
558
|
return -1;
|
|
412
559
|
}
|
|
413
560
|
/**
|
|
561
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
562
|
+
* Space Complexity: O(1)
|
|
563
|
+
*/
|
|
564
|
+
/**
|
|
565
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
566
|
+
* Space Complexity: O(1)
|
|
567
|
+
*
|
|
414
568
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
415
569
|
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
416
570
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
@@ -429,6 +583,13 @@ class DoublyLinkedList {
|
|
|
429
583
|
return null;
|
|
430
584
|
}
|
|
431
585
|
/**
|
|
586
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
587
|
+
* Space Complexity: O(n)
|
|
588
|
+
*/
|
|
589
|
+
/**
|
|
590
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
591
|
+
* Space Complexity: O(n)
|
|
592
|
+
*
|
|
432
593
|
* The `toArrayBackward` function converts a doubly linked list into an array in reverse order.
|
|
433
594
|
* @returns The `toArrayBackward()` function returns an array of type `E[]`.
|
|
434
595
|
*/
|
|
@@ -442,6 +603,13 @@ class DoublyLinkedList {
|
|
|
442
603
|
return array;
|
|
443
604
|
}
|
|
444
605
|
/**
|
|
606
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
607
|
+
* Space Complexity: O(1)
|
|
608
|
+
*/
|
|
609
|
+
/**
|
|
610
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
611
|
+
* Space Complexity: O(1)
|
|
612
|
+
*
|
|
445
613
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
446
614
|
*/
|
|
447
615
|
reverse() {
|
|
@@ -454,6 +622,13 @@ class DoublyLinkedList {
|
|
|
454
622
|
}
|
|
455
623
|
}
|
|
456
624
|
/**
|
|
625
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
626
|
+
* Space Complexity: O(1)
|
|
627
|
+
*/
|
|
628
|
+
/**
|
|
629
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
630
|
+
* Space Complexity: O(1)
|
|
631
|
+
*
|
|
457
632
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
458
633
|
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
459
634
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
@@ -469,6 +644,13 @@ class DoublyLinkedList {
|
|
|
469
644
|
}
|
|
470
645
|
}
|
|
471
646
|
/**
|
|
647
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
648
|
+
* Space Complexity: O(n)
|
|
649
|
+
*/
|
|
650
|
+
/**
|
|
651
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
652
|
+
* Space Complexity: O(n)
|
|
653
|
+
*
|
|
472
654
|
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
|
|
473
655
|
* DoublyLinkedList with the transformed values.
|
|
474
656
|
* @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
|
|
@@ -486,6 +668,13 @@ class DoublyLinkedList {
|
|
|
486
668
|
return mappedList;
|
|
487
669
|
}
|
|
488
670
|
/**
|
|
671
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
672
|
+
* Space Complexity: O(n)
|
|
673
|
+
*/
|
|
674
|
+
/**
|
|
675
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
676
|
+
* Space Complexity: O(n)
|
|
677
|
+
*
|
|
489
678
|
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
|
|
490
679
|
* elements that satisfy the given callback function.
|
|
491
680
|
* @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
|
|
@@ -504,6 +693,13 @@ class DoublyLinkedList {
|
|
|
504
693
|
return filteredList;
|
|
505
694
|
}
|
|
506
695
|
/**
|
|
696
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
697
|
+
* Space Complexity: O(n)
|
|
698
|
+
*/
|
|
699
|
+
/**
|
|
700
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
701
|
+
* Space Complexity: O(n)
|
|
702
|
+
*
|
|
507
703
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
508
704
|
* single value.
|
|
509
705
|
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
@@ -523,6 +719,13 @@ class DoublyLinkedList {
|
|
|
523
719
|
return accumulator;
|
|
524
720
|
}
|
|
525
721
|
/**
|
|
722
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
723
|
+
* Space Complexity: O(1)
|
|
724
|
+
*/
|
|
725
|
+
/**
|
|
726
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
727
|
+
* Space Complexity: O(1)
|
|
728
|
+
*
|
|
526
729
|
* The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
527
730
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
528
731
|
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|