linked-list-typed 1.52.3 → 1.52.5
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/base/iterable-element-base.d.ts +1 -37
- package/dist/data-structures/base/iterable-element-base.js +1 -37
- package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/data-structures/binary-tree/bst.js +12 -44
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/data-structures/graph/abstract-graph.js +0 -75
- package/dist/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/data-structures/graph/directed-graph.js +0 -98
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/data-structures/graph/undirected-graph.js +0 -50
- package/dist/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/data-structures/hash/hash-map.js +29 -115
- package/dist/data-structures/heap/heap.d.ts +0 -32
- package/dist/data-structures/heap/heap.js +0 -32
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/data-structures/queue/deque.d.ts +1 -98
- package/dist/data-structures/queue/deque.js +3 -99
- package/dist/data-structures/queue/queue.d.ts +5 -58
- package/dist/data-structures/queue/queue.js +4 -57
- package/dist/data-structures/stack/stack.d.ts +1 -34
- package/dist/data-structures/stack/stack.js +1 -34
- package/dist/data-structures/tree/tree.js +2 -1
- package/dist/data-structures/trie/trie.d.ts +0 -64
- package/dist/data-structures/trie/trie.js +0 -64
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/utils/utils.d.ts +13 -12
- package/dist/utils/number.d.ts +13 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/utils.d.ts +125 -3
- package/dist/utils/utils.js +177 -21
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +31 -139
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +5 -72
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
|
@@ -133,12 +133,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
133
133
|
return this._size;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
/**
|
|
137
|
-
* Time Complexity: O(1)
|
|
138
|
-
* Space Complexity: O(1)
|
|
139
|
-
* where n is the number of elements in the linked list.
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
136
|
/**
|
|
143
137
|
* Time Complexity: O(1)
|
|
144
138
|
* Space Complexity: O(1)
|
|
@@ -150,11 +144,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
150
144
|
return this.head?.value;
|
|
151
145
|
}
|
|
152
146
|
|
|
153
|
-
/**
|
|
154
|
-
* Time Complexity: O(1)
|
|
155
|
-
* Space Complexity: O(1)
|
|
156
|
-
*/
|
|
157
|
-
|
|
158
147
|
/**
|
|
159
148
|
* Time Complexity: O(1)
|
|
160
149
|
* Space Complexity: O(1)
|
|
@@ -166,11 +155,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
166
155
|
return this.tail?.value;
|
|
167
156
|
}
|
|
168
157
|
|
|
169
|
-
/**
|
|
170
|
-
* Time Complexity: O(n)
|
|
171
|
-
* Space Complexity: O(n)
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
158
|
/**
|
|
175
159
|
* Time Complexity: O(n)
|
|
176
160
|
* Space Complexity: O(n)
|
|
@@ -187,9 +171,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
187
171
|
/**
|
|
188
172
|
* Time Complexity: O(1)
|
|
189
173
|
* Space Complexity: O(1)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
/**
|
|
174
|
+
*
|
|
193
175
|
* The push function adds a new element to the end of a doubly linked list.
|
|
194
176
|
* @param {E} element - The "element" parameter represents the value that you want to add to the
|
|
195
177
|
* doubly linked list.
|
|
@@ -212,9 +194,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
212
194
|
/**
|
|
213
195
|
* Time Complexity: O(1)
|
|
214
196
|
* Space Complexity: O(1)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
/**
|
|
197
|
+
*
|
|
218
198
|
* The `pop()` function removes and returns the value of the last element in a linked list.
|
|
219
199
|
* @returns The method is returning the value of the removed node.
|
|
220
200
|
*/
|
|
@@ -235,9 +215,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
235
215
|
/**
|
|
236
216
|
* Time Complexity: O(1)
|
|
237
217
|
* Space Complexity: O(1)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
/**
|
|
218
|
+
*
|
|
241
219
|
* The `shift()` function removes and returns the value of the first element in a doubly linked list.
|
|
242
220
|
* @returns The value of the removed node.
|
|
243
221
|
*/
|
|
@@ -258,9 +236,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
258
236
|
/**
|
|
259
237
|
* Time Complexity: O(1)
|
|
260
238
|
* Space Complexity: O(1)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
/**
|
|
239
|
+
*
|
|
264
240
|
* The unshift function adds a new element to the beginning of a doubly linked list.
|
|
265
241
|
* @param {E} element - The "element" parameter represents the value of the element that you want to
|
|
266
242
|
* add to the beginning of the doubly linked list.
|
|
@@ -280,11 +256,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
280
256
|
return true;
|
|
281
257
|
}
|
|
282
258
|
|
|
283
|
-
/**
|
|
284
|
-
* Time Complexity: O(n)
|
|
285
|
-
* Space Complexity: O(1)
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
259
|
/**
|
|
289
260
|
* Time Complexity: O(n)
|
|
290
261
|
* Space Complexity: O(1)
|
|
@@ -304,11 +275,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
304
275
|
return current!.value;
|
|
305
276
|
}
|
|
306
277
|
|
|
307
|
-
/**
|
|
308
|
-
* Time Complexity: O(n)
|
|
309
|
-
* Space Complexity: O(1)
|
|
310
|
-
*/
|
|
311
|
-
|
|
312
278
|
/**
|
|
313
279
|
* Time Complexity: O(n)
|
|
314
280
|
* Space Complexity: O(1)
|
|
@@ -329,11 +295,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
329
295
|
return current;
|
|
330
296
|
}
|
|
331
297
|
|
|
332
|
-
/**
|
|
333
|
-
* Time Complexity: O(n)
|
|
334
|
-
* Space Complexity: O(1)
|
|
335
|
-
*/
|
|
336
|
-
|
|
337
298
|
/**
|
|
338
299
|
* Time Complexity: O(n)
|
|
339
300
|
* Space Complexity: O(1)
|
|
@@ -357,11 +318,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
357
318
|
return undefined;
|
|
358
319
|
}
|
|
359
320
|
|
|
360
|
-
/**
|
|
361
|
-
* Time Complexity: O(n)
|
|
362
|
-
* Space Complexity: O(1)
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
321
|
/**
|
|
366
322
|
* Time Complexity: O(n)
|
|
367
323
|
* Space Complexity: O(1)
|
|
@@ -396,12 +352,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
396
352
|
return true;
|
|
397
353
|
}
|
|
398
354
|
|
|
399
|
-
/**
|
|
400
|
-
* Time Complexity: O(1) or O(n)
|
|
401
|
-
* Space Complexity: O(1)
|
|
402
|
-
* where n is the number of elements in the linked list.
|
|
403
|
-
*/
|
|
404
|
-
|
|
405
355
|
/**
|
|
406
356
|
* Time Complexity: O(1) or O(n)
|
|
407
357
|
* Space Complexity: O(1)
|
|
@@ -442,11 +392,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
442
392
|
return false;
|
|
443
393
|
}
|
|
444
394
|
|
|
445
|
-
/**
|
|
446
|
-
* Time Complexity: O(1) or O(n)
|
|
447
|
-
* Space Complexity: O(1)
|
|
448
|
-
*/
|
|
449
|
-
|
|
450
395
|
/**
|
|
451
396
|
* Time Complexity: O(1) or O(n)
|
|
452
397
|
* Space Complexity: O(1)
|
|
@@ -516,11 +461,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
516
461
|
return true;
|
|
517
462
|
}
|
|
518
463
|
|
|
519
|
-
/**
|
|
520
|
-
* Time Complexity: O(1) or O(n)
|
|
521
|
-
* Space Complexity: O(1)
|
|
522
|
-
*/
|
|
523
|
-
|
|
524
464
|
/**
|
|
525
465
|
* Time Complexity: O(1) or O(n)
|
|
526
466
|
* Space Complexity: O(1)
|
|
@@ -557,11 +497,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
557
497
|
return false;
|
|
558
498
|
}
|
|
559
499
|
|
|
560
|
-
/**
|
|
561
|
-
* Time Complexity: O(1)
|
|
562
|
-
* Space Complexity: O(1)
|
|
563
|
-
*/
|
|
564
|
-
|
|
565
500
|
/**
|
|
566
501
|
* Time Complexity: O(1)
|
|
567
502
|
* Space Complexity: O(1)
|
|
@@ -573,11 +508,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
573
508
|
return this.size === 0;
|
|
574
509
|
}
|
|
575
510
|
|
|
576
|
-
/**
|
|
577
|
-
* Time Complexity: O(1)
|
|
578
|
-
* Space Complexity: O(1)
|
|
579
|
-
*/
|
|
580
|
-
|
|
581
511
|
/**
|
|
582
512
|
* Time Complexity: O(1)
|
|
583
513
|
* Space Complexity: O(1)
|
|
@@ -590,11 +520,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
590
520
|
this._size = 0;
|
|
591
521
|
}
|
|
592
522
|
|
|
593
|
-
/**
|
|
594
|
-
* Time Complexity: O(n)
|
|
595
|
-
* Space Complexity: O(1)
|
|
596
|
-
*/
|
|
597
|
-
|
|
598
523
|
/**
|
|
599
524
|
* Time Complexity: O(n)
|
|
600
525
|
* Space Complexity: O(1)
|
|
@@ -618,11 +543,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
618
543
|
return -1;
|
|
619
544
|
}
|
|
620
545
|
|
|
621
|
-
/**
|
|
622
|
-
* Time Complexity: O(n)
|
|
623
|
-
* Space Complexity: O(1)
|
|
624
|
-
*/
|
|
625
|
-
|
|
626
546
|
/**
|
|
627
547
|
* Time Complexity: O(n)
|
|
628
548
|
* Space Complexity: O(1)
|
|
@@ -645,11 +565,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
645
565
|
return undefined;
|
|
646
566
|
}
|
|
647
567
|
|
|
648
|
-
/**
|
|
649
|
-
* Time Complexity: O(n)
|
|
650
|
-
* Space Complexity: O(1)
|
|
651
|
-
*/
|
|
652
|
-
|
|
653
568
|
/**
|
|
654
569
|
* Time Complexity: O(n)
|
|
655
570
|
* Space Complexity: O(1)
|
|
@@ -667,11 +582,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
667
582
|
return this;
|
|
668
583
|
}
|
|
669
584
|
|
|
670
|
-
/**
|
|
671
|
-
* Time Complexity: O(n)
|
|
672
|
-
* Space Complexity: O(n)
|
|
673
|
-
*/
|
|
674
|
-
|
|
675
585
|
/**
|
|
676
586
|
* Time Complexity: O(n)
|
|
677
587
|
* Space Complexity: O(n)
|
|
@@ -689,11 +599,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
689
599
|
return array;
|
|
690
600
|
}
|
|
691
601
|
|
|
692
|
-
/**
|
|
693
|
-
* Time Complexity: O(n)
|
|
694
|
-
* Space Complexity: O(n)
|
|
695
|
-
*/
|
|
696
|
-
|
|
697
602
|
/**
|
|
698
603
|
* Time Complexity: O(n)
|
|
699
604
|
* Space Complexity: O(n)
|
|
@@ -711,11 +616,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
711
616
|
return array;
|
|
712
617
|
}
|
|
713
618
|
|
|
714
|
-
/**
|
|
715
|
-
* Time Complexity: O(n)
|
|
716
|
-
* Space Complexity: O(n)
|
|
717
|
-
*/
|
|
718
|
-
|
|
719
619
|
/**
|
|
720
620
|
* Time Complexity: O(n)
|
|
721
621
|
* Space Complexity: O(n)
|
|
@@ -729,11 +629,6 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
729
629
|
return new DoublyLinkedList<E, R>(this);
|
|
730
630
|
}
|
|
731
631
|
|
|
732
|
-
/**
|
|
733
|
-
* Time Complexity: O(n)
|
|
734
|
-
* Space Complexity: O(n)
|
|
735
|
-
*/
|
|
736
|
-
|
|
737
632
|
/**
|
|
738
633
|
* Time Complexity: O(n)
|
|
739
634
|
* Space Complexity: O(n)
|
|
@@ -766,9 +661,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
766
661
|
/**
|
|
767
662
|
* Time Complexity: O(n)
|
|
768
663
|
* Space Complexity: O(n)
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
/**
|
|
664
|
+
*
|
|
772
665
|
* The `map` function takes a callback function and returns a new DoublyLinkedList with the results
|
|
773
666
|
* of applying the callback to each element in the original list.
|
|
774
667
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
@@ -121,13 +121,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
121
121
|
return this._size;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
/**
|
|
125
|
-
* Time Complexity: O(n)
|
|
126
|
-
* Space Complexity: O(n)
|
|
127
|
-
* Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
128
|
-
* Linear space, as it creates a new node for each element in the array.
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
124
|
/**
|
|
132
125
|
* Time Complexity: O(n)
|
|
133
126
|
* Space Complexity: O(n)
|
|
@@ -145,11 +138,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
145
138
|
return singlyLinkedList;
|
|
146
139
|
}
|
|
147
140
|
|
|
148
|
-
/**
|
|
149
|
-
* Time Complexity: O(1)
|
|
150
|
-
* Space Complexity: O(1)
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
141
|
/**
|
|
154
142
|
* Time Complexity: O(1)
|
|
155
143
|
* Space Complexity: O(1)
|
|
@@ -172,12 +160,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
172
160
|
return true;
|
|
173
161
|
}
|
|
174
162
|
|
|
175
|
-
/**
|
|
176
|
-
* Time Complexity: O(n)
|
|
177
|
-
* Space Complexity: O(1)
|
|
178
|
-
* Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
163
|
/**
|
|
182
164
|
* Time Complexity: O(n)
|
|
183
165
|
* Space Complexity: O(1)
|
|
@@ -207,11 +189,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
207
189
|
return value;
|
|
208
190
|
}
|
|
209
191
|
|
|
210
|
-
/**
|
|
211
|
-
* Time Complexity: O(1)
|
|
212
|
-
* Space Complexity: O(1)
|
|
213
|
-
*/
|
|
214
|
-
|
|
215
192
|
/**
|
|
216
193
|
* Time Complexity: O(1)
|
|
217
194
|
* Space Complexity: O(1)
|
|
@@ -227,11 +204,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
227
204
|
return removedNode.value;
|
|
228
205
|
}
|
|
229
206
|
|
|
230
|
-
/**
|
|
231
|
-
* Time Complexity: O(1)
|
|
232
|
-
* Space Complexity: O(1)
|
|
233
|
-
*/
|
|
234
|
-
|
|
235
207
|
/**
|
|
236
208
|
* Time Complexity: O(1)
|
|
237
209
|
* Space Complexity: O(1)
|
|
@@ -254,11 +226,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
254
226
|
return true;
|
|
255
227
|
}
|
|
256
228
|
|
|
257
|
-
/**
|
|
258
|
-
* Time Complexity: O(n)
|
|
259
|
-
* Space Complexity: O(1)
|
|
260
|
-
*/
|
|
261
|
-
|
|
262
229
|
/**
|
|
263
230
|
* Time Complexity: O(n)
|
|
264
231
|
* Space Complexity: O(1)
|
|
@@ -278,11 +245,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
278
245
|
return current!.value;
|
|
279
246
|
}
|
|
280
247
|
|
|
281
|
-
/**
|
|
282
|
-
* Time Complexity: O(n)
|
|
283
|
-
* Space Complexity: O(1)
|
|
284
|
-
*/
|
|
285
|
-
|
|
286
248
|
/**
|
|
287
249
|
* Time Complexity: O(n)
|
|
288
250
|
* Space Complexity: O(1)
|
|
@@ -301,11 +263,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
301
263
|
return current;
|
|
302
264
|
}
|
|
303
265
|
|
|
304
|
-
/**
|
|
305
|
-
* Time Complexity: O(n)
|
|
306
|
-
* Space Complexity: O(1)
|
|
307
|
-
*/
|
|
308
|
-
|
|
309
266
|
/**
|
|
310
267
|
* Time Complexity: O(n)
|
|
311
268
|
* Space Complexity: O(1)
|
|
@@ -334,11 +291,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
334
291
|
return true;
|
|
335
292
|
}
|
|
336
293
|
|
|
337
|
-
/**
|
|
338
|
-
* Time Complexity: O(n)
|
|
339
|
-
* Space Complexity: O(1)
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
294
|
/**
|
|
343
295
|
* Time Complexity: O(n)
|
|
344
296
|
* Space Complexity: O(1)
|
|
@@ -350,7 +302,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
350
302
|
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
351
303
|
*/
|
|
352
304
|
delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined): boolean {
|
|
353
|
-
if (
|
|
305
|
+
if (valueOrNode === undefined) return false;
|
|
354
306
|
let value: E;
|
|
355
307
|
if (valueOrNode instanceof SinglyLinkedListNode) {
|
|
356
308
|
value = valueOrNode.value;
|
|
@@ -383,11 +335,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
383
335
|
return false;
|
|
384
336
|
}
|
|
385
337
|
|
|
386
|
-
/**
|
|
387
|
-
* Time Complexity: O(n)
|
|
388
|
-
* Space Complexity: O(1)
|
|
389
|
-
*/
|
|
390
|
-
|
|
391
338
|
/**
|
|
392
339
|
* Time Complexity: O(n)
|
|
393
340
|
* Space Complexity: O(1)
|
|
@@ -437,13 +384,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
437
384
|
this._size = 0;
|
|
438
385
|
}
|
|
439
386
|
|
|
440
|
-
/**
|
|
441
|
-
* Time Complexity: O(n)
|
|
442
|
-
* Space Complexity: O(n)
|
|
443
|
-
* Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
|
|
444
|
-
* Linear space, as it creates an array with the same length as the list.
|
|
445
|
-
*/
|
|
446
|
-
|
|
447
387
|
/**
|
|
448
388
|
* Time Complexity: O(n)
|
|
449
389
|
* Space Complexity: O(n)
|
|
@@ -461,11 +401,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
461
401
|
return array;
|
|
462
402
|
}
|
|
463
403
|
|
|
464
|
-
/**
|
|
465
|
-
* Time Complexity: O(n)
|
|
466
|
-
* Space Complexity: O(1)
|
|
467
|
-
*/
|
|
468
|
-
|
|
469
404
|
/**
|
|
470
405
|
* Time Complexity: O(n)
|
|
471
406
|
* Space Complexity: O(1)
|
|
@@ -491,11 +426,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
491
426
|
return this;
|
|
492
427
|
}
|
|
493
428
|
|
|
494
|
-
/**
|
|
495
|
-
* Time Complexity: O(n)
|
|
496
|
-
* Space Complexity: O(1)
|
|
497
|
-
*/
|
|
498
|
-
|
|
499
429
|
/**
|
|
500
430
|
* Time Complexity: O(n)
|
|
501
431
|
* Space Complexity: O(1)
|
|
@@ -520,11 +450,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
520
450
|
return -1;
|
|
521
451
|
}
|
|
522
452
|
|
|
523
|
-
/**
|
|
524
|
-
* Time Complexity: O(n)
|
|
525
|
-
* Space Complexity: O(1)
|
|
526
|
-
*/
|
|
527
|
-
|
|
528
453
|
/**
|
|
529
454
|
* Time Complexity: O(n)
|
|
530
455
|
* Space Complexity: O(1)
|
|
@@ -548,11 +473,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
548
473
|
return undefined;
|
|
549
474
|
}
|
|
550
475
|
|
|
551
|
-
/**
|
|
552
|
-
* Time Complexity: O(n)
|
|
553
|
-
* Space Complexity: O(1)
|
|
554
|
-
*/
|
|
555
|
-
|
|
556
476
|
/**
|
|
557
477
|
* Time Complexity: O(n)
|
|
558
478
|
* Space Complexity: O(1)
|
|
@@ -593,11 +513,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
593
513
|
return false;
|
|
594
514
|
}
|
|
595
515
|
|
|
596
|
-
/**
|
|
597
|
-
* Time Complexity: O(n)
|
|
598
|
-
* Space Complexity: O(1)
|
|
599
|
-
*/
|
|
600
|
-
|
|
601
516
|
/**
|
|
602
517
|
* Time Complexity: O(n)
|
|
603
518
|
* Space Complexity: O(1)
|
|
@@ -632,11 +547,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
632
547
|
return false;
|
|
633
548
|
}
|
|
634
549
|
|
|
635
|
-
/**
|
|
636
|
-
* Time Complexity: O(n)
|
|
637
|
-
* Space Complexity: O(1)
|
|
638
|
-
*/
|
|
639
|
-
|
|
640
550
|
/**
|
|
641
551
|
* Time Complexity: O(n)
|
|
642
552
|
* Space Complexity: O(1)
|
|
@@ -659,11 +569,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
659
569
|
return count;
|
|
660
570
|
}
|
|
661
571
|
|
|
662
|
-
/**
|
|
663
|
-
* Time Complexity: O(n)
|
|
664
|
-
* Space Complexity: O(n)
|
|
665
|
-
*/
|
|
666
|
-
|
|
667
572
|
/**
|
|
668
573
|
* Time Complexity: O(n)
|
|
669
574
|
* Space Complexity: O(n)
|
|
@@ -677,11 +582,6 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
677
582
|
return new SinglyLinkedList<E, R>(this, { toElementFn: this.toElementFn });
|
|
678
583
|
}
|
|
679
584
|
|
|
680
|
-
/**
|
|
681
|
-
* Time Complexity: O(n)
|
|
682
|
-
* Space Complexity: O(n)
|
|
683
|
-
*/
|
|
684
|
-
|
|
685
585
|
/**
|
|
686
586
|
* Time Complexity: O(n)
|
|
687
587
|
* Space Complexity: O(n)
|
|
@@ -714,9 +614,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|
|
714
614
|
/**
|
|
715
615
|
* Time Complexity: O(n)
|
|
716
616
|
* Space Complexity: O(n)
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
/**
|
|
617
|
+
*
|
|
720
618
|
* The `map` function takes a callback function and returns a new SinglyLinkedList with the results
|
|
721
619
|
* of applying the callback to each element in the original list.
|
|
722
620
|
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
@@ -80,11 +80,6 @@ export class SkipList<K, V> {
|
|
|
80
80
|
return this._probability;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* Time Complexity: O(log n)
|
|
85
|
-
* Space Complexity: O(1)
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
83
|
/**
|
|
89
84
|
* Time Complexity: O(1)
|
|
90
85
|
* Space Complexity: O(1)
|
|
@@ -97,11 +92,6 @@ export class SkipList<K, V> {
|
|
|
97
92
|
return firstNode ? firstNode.value : undefined;
|
|
98
93
|
}
|
|
99
94
|
|
|
100
|
-
/**
|
|
101
|
-
* Time Complexity: O(log n)
|
|
102
|
-
* Space Complexity: O(1)
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
95
|
/**
|
|
106
96
|
* Time Complexity: O(log n)
|
|
107
97
|
* Space Complexity: O(1)
|
|
@@ -119,11 +109,6 @@ export class SkipList<K, V> {
|
|
|
119
109
|
return current.value;
|
|
120
110
|
}
|
|
121
111
|
|
|
122
|
-
/**
|
|
123
|
-
* Time Complexity: O(log n)
|
|
124
|
-
* Space Complexity: O(1)
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
112
|
/**
|
|
128
113
|
* Time Complexity: O(log n)
|
|
129
114
|
* Space Complexity: O(1)
|
|
@@ -155,11 +140,6 @@ export class SkipList<K, V> {
|
|
|
155
140
|
}
|
|
156
141
|
}
|
|
157
142
|
|
|
158
|
-
/**
|
|
159
|
-
* Time Complexity: O(log n)
|
|
160
|
-
* Space Complexity: O(1)
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
143
|
/**
|
|
164
144
|
* Time Complexity: O(log n)
|
|
165
145
|
* Space Complexity: O(1)
|
|
@@ -189,9 +169,7 @@ export class SkipList<K, V> {
|
|
|
189
169
|
/**
|
|
190
170
|
* Time Complexity: O(log n)
|
|
191
171
|
* Space Complexity: O(1)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
/**
|
|
172
|
+
*
|
|
195
173
|
* The function checks if a key exists in a data structure.
|
|
196
174
|
* @param {K} key - The parameter "key" is of type K, which represents the type of the key being
|
|
197
175
|
* checked.
|
|
@@ -201,11 +179,6 @@ export class SkipList<K, V> {
|
|
|
201
179
|
return this.get(key) !== undefined;
|
|
202
180
|
}
|
|
203
181
|
|
|
204
|
-
/**
|
|
205
|
-
* Time Complexity: O(log n)
|
|
206
|
-
* Space Complexity: O(1)
|
|
207
|
-
*/
|
|
208
|
-
|
|
209
182
|
/**
|
|
210
183
|
* Time Complexity: O(log n)
|
|
211
184
|
* Space Complexity: O(1)
|
|
@@ -244,11 +217,6 @@ export class SkipList<K, V> {
|
|
|
244
217
|
return false;
|
|
245
218
|
}
|
|
246
219
|
|
|
247
|
-
/**
|
|
248
|
-
* Time Complexity: O(log n)
|
|
249
|
-
* Space Complexity: O(1)
|
|
250
|
-
*/
|
|
251
|
-
|
|
252
220
|
/**
|
|
253
221
|
* Time Complexity: O(log n)
|
|
254
222
|
* Space Complexity: O(1)
|
|
@@ -268,11 +236,6 @@ export class SkipList<K, V> {
|
|
|
268
236
|
return nextNode ? nextNode.value : undefined;
|
|
269
237
|
}
|
|
270
238
|
|
|
271
|
-
/**
|
|
272
|
-
* Time Complexity: O(log n)
|
|
273
|
-
* Space Complexity: O(1)
|
|
274
|
-
*/
|
|
275
|
-
|
|
276
239
|
/**
|
|
277
240
|
* Time Complexity: O(log n)
|
|
278
241
|
* Space Complexity: O(1)
|
|
@@ -297,12 +260,6 @@ export class SkipList<K, V> {
|
|
|
297
260
|
return lastLess ? lastLess.value : undefined;
|
|
298
261
|
}
|
|
299
262
|
|
|
300
|
-
/**
|
|
301
|
-
* Time Complexity: O(maxLevel)
|
|
302
|
-
* Space Complexity: O(1)
|
|
303
|
-
* where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
|
|
304
|
-
*/
|
|
305
|
-
|
|
306
263
|
/**
|
|
307
264
|
* Time Complexity: O(maxLevel)
|
|
308
265
|
* Space Complexity: O(1)
|