min-heap-typed 1.50.1 → 1.50.3

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 (85) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +120 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +72 -47
  4. package/dist/data-structures/binary-tree/avl-tree.js +101 -72
  5. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  8. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  9. package/dist/data-structures/binary-tree/bst.d.ts +92 -79
  10. package/dist/data-structures/binary-tree/bst.js +68 -76
  11. package/dist/data-structures/binary-tree/rb-tree.d.ts +127 -57
  12. package/dist/data-structures/binary-tree/rb-tree.js +152 -99
  13. package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
  14. package/dist/data-structures/binary-tree/segment-tree.js +127 -10
  15. package/dist/data-structures/binary-tree/tree-multimap.d.ts +72 -58
  16. package/dist/data-structures/binary-tree/tree-multimap.js +102 -85
  17. package/dist/data-structures/graph/abstract-graph.d.ts +1 -78
  18. package/dist/data-structures/graph/abstract-graph.js +3 -189
  19. package/dist/data-structures/graph/directed-graph.d.ts +73 -0
  20. package/dist/data-structures/graph/directed-graph.js +131 -0
  21. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  22. package/dist/data-structures/graph/map-graph.js +14 -0
  23. package/dist/data-structures/graph/undirected-graph.d.ts +76 -7
  24. package/dist/data-structures/graph/undirected-graph.js +151 -18
  25. package/dist/data-structures/hash/hash-map.d.ts +254 -28
  26. package/dist/data-structures/hash/hash-map.js +347 -78
  27. package/dist/data-structures/heap/heap.d.ts +95 -25
  28. package/dist/data-structures/heap/heap.js +95 -26
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +141 -77
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +154 -106
  32. package/dist/data-structures/linked-list/singly-linked-list.js +164 -115
  33. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  34. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  35. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  36. package/dist/data-structures/matrix/matrix.js +50 -11
  37. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  38. package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
  39. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  40. package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
  41. package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
  42. package/dist/data-structures/priority-queue/priority-queue.js +8 -0
  43. package/dist/data-structures/queue/deque.d.ts +139 -35
  44. package/dist/data-structures/queue/deque.js +200 -62
  45. package/dist/data-structures/queue/queue.d.ts +103 -49
  46. package/dist/data-structures/queue/queue.js +111 -49
  47. package/dist/data-structures/stack/stack.d.ts +51 -21
  48. package/dist/data-structures/stack/stack.js +58 -22
  49. package/dist/data-structures/tree/tree.d.ts +57 -3
  50. package/dist/data-structures/tree/tree.js +77 -11
  51. package/dist/data-structures/trie/trie.d.ts +135 -34
  52. package/dist/data-structures/trie/trie.js +153 -33
  53. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  54. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  55. package/dist/types/utils/utils.d.ts +1 -0
  56. package/package.json +2 -2
  57. package/src/data-structures/base/iterable-base.ts +184 -19
  58. package/src/data-structures/binary-tree/avl-tree.ts +134 -100
  59. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  60. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  61. package/src/data-structures/binary-tree/bst.ts +127 -136
  62. package/src/data-structures/binary-tree/rb-tree.ts +199 -166
  63. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  64. package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
  65. package/src/data-structures/graph/abstract-graph.ts +4 -211
  66. package/src/data-structures/graph/directed-graph.ts +152 -0
  67. package/src/data-structures/graph/map-graph.ts +15 -0
  68. package/src/data-structures/graph/undirected-graph.ts +171 -19
  69. package/src/data-structures/hash/hash-map.ts +389 -96
  70. package/src/data-structures/heap/heap.ts +97 -26
  71. package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
  72. package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
  73. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  74. package/src/data-structures/matrix/matrix.ts +52 -12
  75. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  76. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  77. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  78. package/src/data-structures/queue/deque.ts +225 -70
  79. package/src/data-structures/queue/queue.ts +118 -49
  80. package/src/data-structures/stack/stack.ts +63 -23
  81. package/src/data-structures/tree/tree.ts +89 -15
  82. package/src/data-structures/trie/trie.ts +173 -38
  83. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  84. package/src/types/data-structures/hash/hash-map.ts +4 -3
  85. package/src/types/utils/utils.ts +2 -0
@@ -9,19 +9,75 @@ import type { ElementCallback } from '../../types';
9
9
  import { IterableElementBase } from '../base';
10
10
 
11
11
  export class DoublyLinkedListNode<E = any> {
12
- value: E;
13
- next: DoublyLinkedListNode<E> | undefined;
14
- prev: DoublyLinkedListNode<E> | undefined;
15
-
16
12
  /**
17
13
  * The constructor function initializes the value, next, and previous properties of an object.
18
14
  * @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
19
15
  * is defined as a generic type "E".
20
16
  */
21
17
  constructor(value: E) {
22
- this.value = value;
23
- this.next = undefined;
24
- this.prev = undefined;
18
+ this._value = value;
19
+ this._next = undefined;
20
+ this._prev = undefined;
21
+ }
22
+
23
+ protected _value: E;
24
+
25
+ /**
26
+ * The function returns the value of a protected variable.
27
+ * @returns The value of the variable `_value` is being returned.
28
+ */
29
+ get value(): E {
30
+ return this._value;
31
+ }
32
+
33
+ /**
34
+ * The above function sets the value of a variable.
35
+ * @param {E} value - The parameter "value" is of type E, which means it can be any type.
36
+ */
37
+ set value(value: E) {
38
+ this._value = value;
39
+ }
40
+
41
+ protected _next: DoublyLinkedListNode<E> | undefined;
42
+
43
+ /**
44
+ * The "next" function returns the next node in a doubly linked list.
45
+ * @returns The `next` property is being returned. It can be either a `DoublyLinkedListNode<E>`
46
+ * object or `undefined`.
47
+ */
48
+ get next(): DoublyLinkedListNode<E> | undefined {
49
+ return this._next;
50
+ }
51
+
52
+ /**
53
+ * The "next" property of a DoublyLinkedListNode is set to the provided value.
54
+ * @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
55
+ * `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
56
+ * `DoublyLinkedListNode` object or `undefined` as its value.
57
+ */
58
+ set next(value: DoublyLinkedListNode<E> | undefined) {
59
+ this._next = value;
60
+ }
61
+
62
+ protected _prev: DoublyLinkedListNode<E> | undefined;
63
+
64
+ /**
65
+ * The `prev` function returns the previous node in a doubly linked list.
66
+ * @returns The `prev` property of the `DoublyLinkedListNode` class is being returned. It can either
67
+ * be a `DoublyLinkedListNode` object or `undefined`.
68
+ */
69
+ get prev(): DoublyLinkedListNode<E> | undefined {
70
+ return this._prev;
71
+ }
72
+
73
+ /**
74
+ * The function sets the previous node of a doubly linked list node.
75
+ * @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
76
+ * `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
77
+ * `DoublyLinkedListNode` object or `undefined` as its value.
78
+ */
79
+ set prev(value: DoublyLinkedListNode<E> | undefined) {
80
+ this._prev = value;
25
81
  }
26
82
  }
27
83
 
@@ -33,7 +89,10 @@ export class DoublyLinkedListNode<E = any> {
33
89
  */
34
90
  export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
35
91
  /**
36
- * The constructor initializes the linked list with an empty head, tail, and size.
92
+ * The constructor initializes a linked list with optional elements.
93
+ * @param elements - The `elements` parameter is an optional iterable object that contains the
94
+ * initial elements to be added to the data structure. It defaults to an empty array if no elements
95
+ * are provided.
37
96
  */
38
97
  constructor(elements: Iterable<E> = []) {
39
98
  super();
@@ -49,29 +108,43 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
49
108
 
50
109
  protected _head: DoublyLinkedListNode<E> | undefined;
51
110
 
111
+ /**
112
+ * The `head` function returns the first node of a doubly linked list.
113
+ * @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
114
+ */
52
115
  get head(): DoublyLinkedListNode<E> | undefined {
53
116
  return this._head;
54
117
  }
55
118
 
56
119
  protected _tail: DoublyLinkedListNode<E> | undefined;
57
120
 
121
+ /**
122
+ * The `tail` function returns the last node of a doubly linked list.
123
+ * @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
124
+ * `undefined`.
125
+ */
58
126
  get tail(): DoublyLinkedListNode<E> | undefined {
59
127
  return this._tail;
60
128
  }
61
129
 
62
130
  protected _size: number;
63
131
 
132
+ /**
133
+ * The function returns the size of an object.
134
+ * @returns The size of the object, which is a number.
135
+ */
64
136
  get size(): number {
65
137
  return this._size;
66
138
  }
67
139
 
68
140
  /**
69
- * Time Complexity: O(n), where n is the size of the input array.
70
- * Space Complexity: O(n)
141
+ * Time Complexity: O(1)
142
+ * Space Complexity: O(1)
143
+ * where n is the number of elements in the linked list.
71
144
  */
72
145
 
73
146
  /**
74
- * Time Complexity: O(n), where n is the number of elements in the linked list.
147
+ * Time Complexity: O(1)
75
148
  * Space Complexity: O(1)
76
149
  *
77
150
  * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
@@ -87,7 +160,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
87
160
  */
88
161
 
89
162
  /**
90
- * Time Complexity: O(n), where n is the number of elements in the linked list.
163
+ * Time Complexity: O(1)
91
164
  * Space Complexity: O(1)
92
165
  *
93
166
  * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
@@ -98,12 +171,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
98
171
  }
99
172
 
100
173
  /**
101
- * Time Complexity: O(1)
102
- * Space Complexity: O(1)
174
+ * Time Complexity: O(n)
175
+ * Space Complexity: O(n)
103
176
  */
104
177
 
105
178
  /**
106
- * Time Complexity: O(n), where n is the size of the input array.
179
+ * Time Complexity: O(n)
107
180
  * Space Complexity: O(n)
108
181
  *
109
182
  * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
@@ -112,11 +185,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
112
185
  * @returns The `fromArray` function returns a DoublyLinkedList object.
113
186
  */
114
187
  static fromArray<E>(data: E[]) {
115
- const doublyLinkedList = new DoublyLinkedList<E>();
116
- for (const item of data) {
117
- doublyLinkedList.push(item);
118
- }
119
- return doublyLinkedList;
188
+ return new DoublyLinkedList<E>(data);
120
189
  }
121
190
 
122
191
  /**
@@ -173,7 +242,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
173
242
  }
174
243
 
175
244
  /**
176
- * Time Complexity: O(n), where n is the number of elements in the linked list.
245
+ * Time Complexity: O(1)
177
246
  * Space Complexity: O(1)
178
247
  */
179
248
 
@@ -200,7 +269,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
200
269
  }
201
270
 
202
271
  /**
203
- * Time Complexity: O(n), where n is the number of elements in the linked list.
272
+ * Time Complexity: O(1)
204
273
  * Space Complexity: O(1)
205
274
  */
206
275
 
@@ -227,21 +296,21 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
227
296
  }
228
297
 
229
298
  /**
230
- * Time Complexity: O(n), where n is the number of elements in the linked list.
299
+ * Time Complexity: O(n)
231
300
  * Space Complexity: O(1)
232
301
  */
233
302
 
234
303
  /**
235
- * Time Complexity: O(n), where n is the number of elements in the linked list.
304
+ * Time Complexity: O(n)
236
305
  * Space Complexity: O(1)
237
306
  *
238
- * The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
307
+ * The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
239
308
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
240
309
  * retrieve from the list.
241
310
  * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
242
311
  * or the linked list is empty, it will return undefined.
243
312
  */
244
- getAt(index: number): E | undefined {
313
+ at(index: number): E | undefined {
245
314
  if (index < 0 || index >= this.size) return undefined;
246
315
  let current = this.head;
247
316
  for (let i = 0; i < index; i++) {
@@ -251,12 +320,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
251
320
  }
252
321
 
253
322
  /**
254
- * Time Complexity: O(n), where n is the number of elements in the linked list.
323
+ * Time Complexity: O(n)
255
324
  * Space Complexity: O(1)
256
325
  */
257
326
 
258
327
  /**
259
- * Time Complexity: O(n), where n is the number of elements in the linked list.
328
+ * Time Complexity: O(n)
260
329
  * Space Complexity: O(1)
261
330
  *
262
331
  * The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
@@ -276,12 +345,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
276
345
  }
277
346
 
278
347
  /**
279
- * Time Complexity: O(n), where n is the number of elements in the linked list.
348
+ * Time Complexity: O(n)
280
349
  * Space Complexity: O(1)
281
350
  */
282
351
 
283
352
  /**
284
- * Time Complexity: O(n), where n is the number of elements in the linked list.
353
+ * Time Complexity: O(n)
285
354
  * Space Complexity: O(1)
286
355
  *
287
356
  * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
@@ -304,12 +373,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
304
373
  }
305
374
 
306
375
  /**
307
- * Time Complexity: O(n), where n is the number of elements in the linked list.
376
+ * Time Complexity: O(n)
308
377
  * Space Complexity: O(1)
309
378
  */
310
379
 
311
380
  /**
312
- * Time Complexity: O(n), where n is the number of elements in the linked list.
381
+ * Time Complexity: O(n)
313
382
  * Space Complexity: O(1)
314
383
  *
315
384
  * The `insert` function inserts a value at a specified index in a doubly linked list.
@@ -343,12 +412,13 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
343
412
  }
344
413
 
345
414
  /**
346
- * Time Complexity: O(n), where n is the number of elements in the linked list.
415
+ * Time Complexity: O(1) or O(n)
347
416
  * Space Complexity: O(1)
417
+ * where n is the number of elements in the linked list.
348
418
  */
349
419
 
350
420
  /**
351
- * Time Complexity: O(n), where n is the number of elements in the linked list.
421
+ * Time Complexity: O(1) or O(n)
352
422
  * Space Complexity: O(1)
353
423
  *
354
424
  * The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
@@ -388,12 +458,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
388
458
  }
389
459
 
390
460
  /**
391
- * Time Complexity: O(n), where n is the number of elements in the linked list.
461
+ * Time Complexity: O(1) or O(n)
392
462
  * Space Complexity: O(1)
393
463
  */
394
464
 
395
465
  /**
396
- * Time Complexity: O(n), where n is the number of elements in the linked list.
466
+ * Time Complexity: O(1) or O(n)
397
467
  * Space Complexity: O(1)
398
468
  *
399
469
  * The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
@@ -432,7 +502,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
432
502
  }
433
503
 
434
504
  /**
435
- * Time Complexity: O(n), where n is the number of elements in the linked list.
505
+ * Time Complexity: O(n)
436
506
  * Space Complexity: O(1)
437
507
  *
438
508
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
@@ -462,7 +532,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
462
532
  }
463
533
 
464
534
  /**
465
- * Time Complexity: O(n), where n is the number of elements in the linked list.
535
+ * Time Complexity: O(1) or O(n)
536
+ * Space Complexity: O(1)
537
+ */
538
+
539
+ /**
540
+ * Time Complexity: O(1) or O(n)
466
541
  * Space Complexity: O(1)
467
542
  *
468
543
  * The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
@@ -498,11 +573,14 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
498
573
  }
499
574
 
500
575
  /**
501
- * Time Complexity: O(n), where n is the number of elements in the linked list.
576
+ * Time Complexity: O(1)
502
577
  * Space Complexity: O(1)
503
578
  */
504
579
 
505
580
  /**
581
+ * Time Complexity: O(1)
582
+ * Space Complexity: O(1)
583
+ *
506
584
  * The function checks if a variable has a size greater than zero and returns a boolean value.
507
585
  * @returns A boolean value is being returned.
508
586
  */
@@ -511,11 +589,14 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
511
589
  }
512
590
 
513
591
  /**
514
- * Time Complexity: O(n), where n is the number of elements in the linked list.
592
+ * Time Complexity: O(1)
515
593
  * Space Complexity: O(1)
516
594
  */
517
595
 
518
596
  /**
597
+ * Time Complexity: O(1)
598
+ * Space Complexity: O(1)
599
+ *
519
600
  * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
520
601
  */
521
602
  clear(): void {
@@ -525,38 +606,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
525
606
  }
526
607
 
527
608
  /**
528
- * Time Complexity: O(n), where n is the number of elements in the linked list.
529
- * Space Complexity: O(1)
530
- */
531
-
532
- /**
533
- * Time Complexity: O(n), where n is the number of elements in the linked list.
534
- * Space Complexity: O(1)
535
- *
536
- * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
537
- * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
538
- * function is used to determine whether a particular value in the linked list satisfies a certain condition.
539
- * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
540
- * the callback function. If no element satisfies the condition, it returns `undefined`.
541
- */
542
- find(callback: (value: E) => boolean): E | undefined {
543
- let current = this.head;
544
- while (current) {
545
- if (callback(current.value)) {
546
- return current.value;
547
- }
548
- current = current.next;
549
- }
550
- return undefined;
551
- }
552
-
553
- /**
554
- * Time Complexity: O(n), where n is the number of elements in the linked list.
609
+ * Time Complexity: O(n)
555
610
  * Space Complexity: O(1)
556
611
  */
557
612
 
558
613
  /**
559
- * Time Complexity: O(n), where n is the number of elements in the linked list.
614
+ * Time Complexity: O(n)
560
615
  * Space Complexity: O(1)
561
616
  *
562
617
  * The function returns the index of the first occurrence of a given value in a linked list.
@@ -579,12 +634,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
579
634
  }
580
635
 
581
636
  /**
582
- * Time Complexity: O(n), where n is the number of elements in the linked list.
583
- * Space Complexity: O(n)
637
+ * Time Complexity: O(n)
638
+ * Space Complexity: O(1)
584
639
  */
585
640
 
586
641
  /**
587
- * Time Complexity: O(n), where n is the number of elements in the linked list.
642
+ * Time Complexity: O(n)
588
643
  * Space Complexity: O(1)
589
644
  *
590
645
  * The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
@@ -606,12 +661,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
606
661
  }
607
662
 
608
663
  /**
609
- * Time Complexity: O(n), where n is the number of elements in the linked list.
610
- * Space Complexity: O(n)
664
+ * Time Complexity: O(n)
665
+ * Space Complexity: O(1)
611
666
  */
612
667
 
613
668
  /**
614
- * Time Complexity: O(n), where n is the number of elements in the linked list.
669
+ * Time Complexity: O(n)
615
670
  * Space Complexity: O(1)
616
671
  *
617
672
  * The `reverse` function reverses the order of the elements in a doubly linked list.
@@ -633,7 +688,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
633
688
  */
634
689
 
635
690
  /**
636
- * Time Complexity: O(n), where n is the number of elements in the linked list.
691
+ * Time Complexity: O(n)
637
692
  * Space Complexity: O(n)
638
693
  *
639
694
  * The `toArray` function converts a linked list into an array.
@@ -650,12 +705,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
650
705
  }
651
706
 
652
707
  /**
653
- * Time Complexity: O(n), where n is the number of elements in the linked list.
708
+ * Time Complexity: O(n)
654
709
  * Space Complexity: O(n)
655
710
  */
656
711
 
657
712
  /**
658
- * Time Complexity: O(n), where n is the number of elements in the linked list.
713
+ * Time Complexity: O(n)
659
714
  * Space Complexity: O(n)
660
715
  *
661
716
  * The `toReversedArray` function converts a doubly linked list into an array in reverse order.
@@ -672,8 +727,26 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
672
727
  }
673
728
 
674
729
  /**
675
- * Time Complexity: O(1)
676
- * Space Complexity: O(1)
730
+ * Time Complexity: O(n)
731
+ * Space Complexity: O(n)
732
+ */
733
+
734
+ /**
735
+ * Time Complexity: O(n)
736
+ * Space Complexity: O(n)
737
+ *
738
+ * The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
739
+ * as the original list.
740
+ * @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
741
+ * is a copy of the original list.
742
+ */
743
+ clone(): DoublyLinkedList<E> {
744
+ return new DoublyLinkedList(this.values());
745
+ }
746
+
747
+ /**
748
+ * Time Complexity: O(n)
749
+ * Space Complexity: O(n)
677
750
  */
678
751
 
679
752
  /**
@@ -706,8 +779,8 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
706
779
  }
707
780
 
708
781
  /**
709
- * Time Complexity: O(1)
710
- * Space Complexity: O(1)
782
+ * Time Complexity: O(n)
783
+ * Space Complexity: O(n)
711
784
  */
712
785
 
713
786
  /**
@@ -772,7 +845,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
772
845
  }
773
846
 
774
847
  /**
775
- * Time Complexity: O(n), where n is the number of elements in the linked list.
848
+ * Time Complexity: O(1)
776
849
  * Space Complexity: O(1)
777
850
  */
778
851
 
@@ -789,7 +862,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
789
862
  }
790
863
 
791
864
  /**
792
- * Time Complexity: O(n), where n is the number of elements in the linked list.
865
+ * Time Complexity: O(1)
793
866
  * Space Complexity: O(1)
794
867
  */
795
868