min-heap-typed 1.50.1 → 1.50.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.
Files changed (67) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +114 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
  4. package/dist/data-structures/binary-tree/avl-tree.js +68 -71
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  6. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  7. package/dist/data-structures/binary-tree/bst.d.ts +54 -74
  8. package/dist/data-structures/binary-tree/bst.js +30 -71
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
  10. package/dist/data-structures/binary-tree/rb-tree.js +84 -89
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  12. package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
  13. package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
  14. package/dist/data-structures/graph/abstract-graph.js +3 -0
  15. package/dist/data-structures/graph/directed-graph.d.ts +14 -0
  16. package/dist/data-structures/graph/directed-graph.js +26 -0
  17. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  18. package/dist/data-structures/graph/map-graph.js +14 -0
  19. package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
  20. package/dist/data-structures/graph/undirected-graph.js +25 -0
  21. package/dist/data-structures/hash/hash-map.d.ts +121 -15
  22. package/dist/data-structures/hash/hash-map.js +160 -25
  23. package/dist/data-structures/heap/heap.d.ts +66 -6
  24. package/dist/data-structures/heap/heap.js +66 -6
  25. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  26. package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
  27. package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  28. package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
  29. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  30. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  31. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  32. package/dist/data-structures/matrix/matrix.js +50 -11
  33. package/dist/data-structures/queue/deque.d.ts +49 -19
  34. package/dist/data-structures/queue/deque.js +101 -47
  35. package/dist/data-structures/queue/queue.d.ts +39 -5
  36. package/dist/data-structures/queue/queue.js +47 -5
  37. package/dist/data-structures/stack/stack.d.ts +16 -0
  38. package/dist/data-structures/stack/stack.js +22 -0
  39. package/dist/data-structures/trie/trie.d.ts +38 -1
  40. package/dist/data-structures/trie/trie.js +41 -0
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  42. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  43. package/dist/types/utils/utils.d.ts +1 -0
  44. package/package.json +2 -2
  45. package/src/data-structures/base/iterable-base.ts +172 -19
  46. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  47. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  48. package/src/data-structures/binary-tree/bst.ts +89 -131
  49. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  50. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  51. package/src/data-structures/graph/abstract-graph.ts +4 -0
  52. package/src/data-structures/graph/directed-graph.ts +30 -0
  53. package/src/data-structures/graph/map-graph.ts +15 -0
  54. package/src/data-structures/graph/undirected-graph.ts +28 -0
  55. package/src/data-structures/hash/hash-map.ts +175 -34
  56. package/src/data-structures/heap/heap.ts +66 -6
  57. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  58. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  59. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  60. package/src/data-structures/matrix/matrix.ts +52 -12
  61. package/src/data-structures/queue/deque.ts +108 -49
  62. package/src/data-structures/queue/queue.ts +51 -5
  63. package/src/data-structures/stack/stack.ts +24 -0
  64. package/src/data-structures/trie/trie.ts +45 -1
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  66. package/src/types/data-structures/hash/hash-map.ts +4 -3
  67. package/src/types/utils/utils.ts +2 -0
@@ -25,7 +25,10 @@ export class SinglyLinkedListNode<E = any> {
25
25
 
26
26
  export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
27
27
  /**
28
- * The constructor initializes the linked list with an empty head, tail, and length.
28
+ * The constructor initializes a new instance of a class with an optional iterable of elements.
29
+ * @param elements - The `elements` parameter is an optional iterable object that contains the
30
+ * initial elements to be added to the instance of the class. If no `elements` are provided, an empty
31
+ * array will be used as the default value.
29
32
  */
30
33
  constructor(elements: Iterable<E> = []) {
31
34
  super();
@@ -36,30 +39,44 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
36
39
 
37
40
  protected _head: SinglyLinkedListNode<E> | undefined;
38
41
 
42
+ /**
43
+ * The `head` function returns the first node of a singly linked list.
44
+ * @returns The method is returning either a SinglyLinkedListNode object or undefined.
45
+ */
39
46
  get head(): SinglyLinkedListNode<E> | undefined {
40
47
  return this._head;
41
48
  }
42
49
 
43
50
  protected _tail: SinglyLinkedListNode<E> | undefined;
44
51
 
52
+ /**
53
+ * The `tail` function returns the last node of a singly linked list.
54
+ * @returns The method is returning either a SinglyLinkedListNode object or undefined.
55
+ */
45
56
  get tail(): SinglyLinkedListNode<E> | undefined {
46
57
  return this._tail;
47
58
  }
48
59
 
49
60
  protected _size: number = 0;
50
61
 
62
+ /**
63
+ * The function returns the size of an object.
64
+ * @returns The size of the object, which is a number.
65
+ */
51
66
  get size(): number {
52
67
  return this._size;
53
68
  }
54
69
 
55
70
  /**
56
- * 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.
57
- * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
71
+ * Time Complexity: O(n)
72
+ * Space Complexity: O(n)
73
+ * Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
74
+ * Linear space, as it creates a new node for each element in the array.
58
75
  */
59
76
 
60
77
  /**
61
- * 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.
62
- * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
78
+ * Time Complexity: O(n)
79
+ * Space Complexity: O(n)
63
80
  *
64
81
  * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
65
82
  * array.
@@ -75,13 +92,15 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
75
92
  }
76
93
 
77
94
  /**
78
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
79
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
95
+ * Time Complexity: O(1)
96
+ * Space Complexity: O(1)
97
+ * Constant time, as it involves basic pointer adjustments.
98
+ * Constant space, as it only creates a new node.
80
99
  */
81
100
 
82
101
  /**
83
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
84
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
102
+ * Time Complexity: O(1)
103
+ * Space Complexity: O(1)
85
104
  *
86
105
  * The `push` function adds a new node with the given value to the end of a singly linked list.
87
106
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
@@ -101,13 +120,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
101
120
  }
102
121
 
103
122
  /**
104
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
105
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
123
+ * Time Complexity: O(1)
124
+ * Space Complexity: O(1)
106
125
  */
107
126
 
108
127
  /**
109
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
110
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
128
+ * Time Complexity: O(1)
129
+ * Space Complexity: O(1)
111
130
  *
112
131
  * The `push` function adds a new node with the given value to the end of a singly linked list.
113
132
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
@@ -118,13 +137,14 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
118
137
  }
119
138
 
120
139
  /**
121
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
122
- * Space Complexity: O(1) - Constant space.
140
+ * Time Complexity: O(n)
141
+ * Space Complexity: O(1)
142
+ * Linear time in the worst case, as it may need to traverse the list to find the last element.
123
143
  */
124
144
 
125
145
  /**
126
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
127
- * Space Complexity: O(1) - Constant space.
146
+ * Time Complexity: O(n)
147
+ * Space Complexity: O(1)
128
148
  *
129
149
  * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
130
150
  * pointers accordingly.
@@ -153,13 +173,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
153
173
  }
154
174
 
155
175
  /**
156
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
157
- * Space Complexity: O(1) - Constant space.
176
+ * Time Complexity: O(n)
177
+ * Space Complexity: O(1)
158
178
  */
159
179
 
160
180
  /**
161
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
162
- * Space Complexity: O(1) - Constant space.
181
+ * Time Complexity: O(n)
182
+ * Space Complexity: O(1)
163
183
  *
164
184
  * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
165
185
  * pointers accordingly.
@@ -171,13 +191,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
171
191
  }
172
192
 
173
193
  /**
174
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
175
- * Space Complexity: O(1) - Constant space.
194
+ * Time Complexity: O(1)
195
+ * Space Complexity: O(1)
176
196
  */
177
197
 
178
198
  /**
179
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
180
- * Space Complexity: O(1) - Constant space.
199
+ * Time Complexity: O(1)
200
+ * Space Complexity: O(1)
181
201
  *
182
202
  * The `shift()` function removes and returns the value of the first node in a linked list.
183
203
  * @returns The value of the node that is being removed from the beginning of the linked list.
@@ -191,13 +211,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
191
211
  }
192
212
 
193
213
  /**
194
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
195
- * Space Complexity: O(1) - Constant space.
214
+ * Time Complexity: O(1)
215
+ * Space Complexity: O(1)
196
216
  */
197
217
 
198
218
  /**
199
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
200
- * Space Complexity: O(1) - Constant space.
219
+ * Time Complexity: O(1)
220
+ * Space Complexity: O(1)
201
221
  *
202
222
  * The `pollFirst()` function removes and returns the value of the first node in a linked list.
203
223
  * @returns The value of the node that is being removed from the beginning of the linked list.
@@ -207,13 +227,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
207
227
  }
208
228
 
209
229
  /**
210
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
211
- * Space Complexity: O(1) - Constant space.
230
+ * Time Complexity: O(1)
231
+ * Space Complexity: O(1)
212
232
  */
213
233
 
214
234
  /**
215
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
216
- * Space Complexity: O(1) - Constant space.
235
+ * Time Complexity: O(1)
236
+ * Space Complexity: O(1)
217
237
  *
218
238
  * The unshift function adds a new node with the given value to the beginning of a singly linked list.
219
239
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
@@ -233,13 +253,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
233
253
  }
234
254
 
235
255
  /**
236
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
237
- * Space Complexity: O(1) - Constant space.
256
+ * Time Complexity: O(1)
257
+ * Space Complexity: O(1)
238
258
  */
239
259
 
240
260
  /**
241
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
242
- * Space Complexity: O(1) - Constant space.
261
+ * Time Complexity: O(1)
262
+ * Space Complexity: O(1)
243
263
  *
244
264
  * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
245
265
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
@@ -250,21 +270,22 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
250
270
  }
251
271
 
252
272
  /**
253
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
254
- * Space Complexity: O(1) - Constant space.
273
+ * Time Complexity: O(n)
274
+ * Space Complexity: O(1)
275
+ * Linear time, where n is the index, as it may need to traverse the list to find the desired node.
255
276
  */
256
277
 
257
278
  /**
258
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
259
- * Space Complexity: O(1) - Constant space.
279
+ * Time Complexity: O(n)
280
+ * Space Complexity: O(1)
260
281
  *
261
- * The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
282
+ * The function `at` returns the value at a specified index in a linked list, or undefined if the index is out of range.
262
283
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
263
284
  * retrieve from the list.
264
- * @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
285
+ * @returns The method `at(index: number): E | undefined` returns the value at the specified index in the linked list, or
265
286
  * `undefined` if the index is out of bounds.
266
287
  */
267
- getAt(index: number): E | undefined {
288
+ at(index: number): E | undefined {
268
289
  if (index < 0 || index >= this.size) return undefined;
269
290
  let current = this.head;
270
291
  for (let i = 0; i < index; i++) {
@@ -274,13 +295,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
274
295
  }
275
296
 
276
297
  /**
277
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
278
- * Space Complexity: O(1) - Constant space.
298
+ * Time Complexity: O(n)
299
+ * Space Complexity: O(1)
279
300
  */
280
301
 
281
302
  /**
282
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
283
- * Space Complexity: O(1) - Constant space.
303
+ * Time Complexity: O(n)
304
+ * Space Complexity: O(1)
284
305
  *
285
306
  * The function `getNodeAt` returns the node at a given index in a singly linked list.
286
307
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
@@ -297,13 +318,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
297
318
  }
298
319
 
299
320
  /**
300
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
301
- * Space Complexity: O(1) - Constant space.
321
+ * Time Complexity: O(n)
322
+ * Space Complexity: O(1)
302
323
  */
303
324
 
304
325
  /**
305
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
306
- * Space Complexity: O(1) - Constant space.
326
+ * Time Complexity: O(n)
327
+ * Space Complexity: O(1)
307
328
  *
308
329
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
309
330
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
@@ -330,13 +351,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
330
351
  }
331
352
 
332
353
  /**
333
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
334
- * Space Complexity: O(1) - Constant space.
354
+ * Time Complexity: O(n)
355
+ * Space Complexity: O(1)
335
356
  */
336
357
 
337
358
  /**
338
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
339
- * Space Complexity: O(1) - Constant space.
359
+ * Time Complexity: O(n)
360
+ * Space Complexity: O(1)
340
361
  *
341
362
  * The delete function removes a node with a specific value from a singly linked list.
342
363
  * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
@@ -379,13 +400,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
379
400
  }
380
401
 
381
402
  /**
382
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
383
- * Space Complexity: O(1) - Constant space.
403
+ * Time Complexity: O(n)
404
+ * Space Complexity: O(1)
384
405
  */
385
406
 
386
407
  /**
387
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
388
- * Space Complexity: O(1) - Constant space.
408
+ * Time Complexity: O(n)
409
+ * Space Complexity: O(1)
389
410
  *
390
411
  * The `addAt` function inserts a value at a specified index in a singly linked list.
391
412
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
@@ -433,13 +454,15 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
433
454
  }
434
455
 
435
456
  /**
436
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
437
- * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
457
+ * Time Complexity: O(n)
458
+ * Space Complexity: O(n)
459
+ * Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
460
+ * Linear space, as it creates an array with the same length as the list.
438
461
  */
439
462
 
440
463
  /**
441
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
442
- * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
464
+ * Time Complexity: O(n)
465
+ * Space Complexity: O(n)
443
466
  *
444
467
  * The `toArray` function converts a linked list into an array.
445
468
  * @returns The `toArray()` method is returning an array of type `E[]`.
@@ -455,13 +478,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
455
478
  }
456
479
 
457
480
  /**
458
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
459
- * Space Complexity: O(1) - Constant space.
481
+ * Time Complexity: O(n)
482
+ * Space Complexity: O(1)
460
483
  */
461
484
 
462
485
  /**
463
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
464
- * Space Complexity: O(1) - Constant space.
486
+ * Time Complexity: O(n)
487
+ * Space Complexity: O(1)
465
488
  *
466
489
  * The `reverse` function reverses the order of the nodes in a singly linked list.
467
490
  * @returns The reverse() method does not return anything. It has a return type of void.
@@ -485,39 +508,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
485
508
  }
486
509
 
487
510
  /**
488
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
489
- * Space Complexity: O(1) - Constant space.
490
- */
491
-
492
- /**
493
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
494
- * Space Complexity: O(1) - Constant space.
495
- *
496
- * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
497
- * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
498
- * function is used to determine whether a particular value in the linked list satisfies a certain condition.
499
- * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
500
- * the callback function. If no element satisfies the condition, it returns `undefined`.
501
- */
502
- find(callback: (value: E) => boolean): E | undefined {
503
- let current = this.head;
504
- while (current) {
505
- if (callback(current.value)) {
506
- return current.value;
507
- }
508
- current = current.next;
509
- }
510
- return undefined;
511
- }
512
-
513
- /**
514
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
515
- * Space Complexity: O(1) - Constant space.
511
+ * Time Complexity: O(n)
512
+ * Space Complexity: O(1)
516
513
  */
517
514
 
518
515
  /**
519
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
520
- * Space Complexity: O(1) - Constant space.
516
+ * Time Complexity: O(n)
517
+ * Space Complexity: O(1)
521
518
  *
522
519
  * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
523
520
  * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
@@ -540,13 +537,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
540
537
  }
541
538
 
542
539
  /**
543
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
544
- * Space Complexity: O(1) - Constant space.
540
+ * Time Complexity: O(n)
541
+ * Space Complexity: O(1)
545
542
  */
546
543
 
547
544
  /**
548
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
549
- * Space Complexity: O(1) - Constant space.
545
+ * Time Complexity: O(n)
546
+ * Space Complexity: O(1)
550
547
  *
551
548
  * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
552
549
  * undefined.
@@ -568,13 +565,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
568
565
  }
569
566
 
570
567
  /**
571
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
572
- * Space Complexity: O(1) - Constant space.
568
+ * Time Complexity: O(n)
569
+ * Space Complexity: O(1)
573
570
  */
574
571
 
575
572
  /**
576
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
577
- * Space Complexity: O(1) - Constant space.
573
+ * Time Complexity: O(n)
574
+ * Space Complexity: O(1)
578
575
  *
579
576
  * The `addBefore` function inserts a new value before an existing value in a singly linked list.
580
577
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
@@ -613,13 +610,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
613
610
  }
614
611
 
615
612
  /**
616
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
617
- * Space Complexity: O(1) - Constant space.
613
+ * Time Complexity: O(n)
614
+ * Space Complexity: O(1)
618
615
  */
619
616
 
620
617
  /**
621
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
622
- * Space Complexity: O(1) - Constant space.
618
+ * Time Complexity: O(n)
619
+ * Space Complexity: O(1)
623
620
  *
624
621
  * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
625
622
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
@@ -652,13 +649,13 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
652
649
  }
653
650
 
654
651
  /**
655
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
656
- * Space Complexity: O(1) - Constant space.
652
+ * Time Complexity: O(n)
653
+ * Space Complexity: O(1)
657
654
  */
658
655
 
659
656
  /**
660
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
661
- * Space Complexity: O(1) - Constant space.
657
+ * Time Complexity: O(n)
658
+ * Space Complexity: O(1)
662
659
  *
663
660
  * The function counts the number of occurrences of a given value in a linked list.
664
661
  * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
@@ -678,6 +675,24 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
678
675
  return count;
679
676
  }
680
677
 
678
+ /**
679
+ * Time Complexity: O(n)
680
+ * Space Complexity: O(n)
681
+ */
682
+
683
+ /**
684
+ * Time Complexity: O(n)
685
+ * Space Complexity: O(n)
686
+ *
687
+ * The `clone` function returns a new instance of the `SinglyLinkedList` class with the same values
688
+ * as the original list.
689
+ * @returns The `clone()` method is returning a new instance of the `SinglyLinkedList` class, which
690
+ * is a clone of the original list.
691
+ */
692
+ clone(): SinglyLinkedList<E> {
693
+ return new SinglyLinkedList<E>(this.values());
694
+ }
695
+
681
696
  /**
682
697
  * Time Complexity: O(n)
683
698
  * Space Complexity: O(n)
@@ -741,6 +756,9 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
741
756
  return mappedList;
742
757
  }
743
758
 
759
+ /**
760
+ * The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
761
+ */
744
762
  protected* _getIterator(): IterableIterator<E> {
745
763
  let current = this.head;
746
764