data-structure-typed 1.50.4 → 1.50.6

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 (82) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +116 -55
  3. package/SPECIFICATION.md +2 -2
  4. package/SPECIFICATION_zh-CN.md +81 -0
  5. package/{SPONSOR-zh-CN.md → SPONSOR_zh-CN.md} +1 -1
  6. package/benchmark/report.html +24 -24
  7. package/benchmark/report.json +261 -237
  8. package/dist/cjs/data-structures/base/iterable-base.d.ts +10 -8
  9. package/dist/cjs/data-structures/base/iterable-base.js +8 -12
  10. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -19
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js +415 -386
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  17. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +84 -76
  18. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  19. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  20. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
  21. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  23. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
  24. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +16 -86
  25. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +35 -79
  28. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  29. package/dist/cjs/data-structures/queue/deque.d.ts +0 -53
  30. package/dist/cjs/data-structures/queue/deque.js +0 -61
  31. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  32. package/dist/cjs/data-structures/queue/queue.d.ts +0 -70
  33. package/dist/cjs/data-structures/queue/queue.js +0 -87
  34. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  35. package/dist/mjs/data-structures/base/iterable-base.d.ts +10 -8
  36. package/dist/mjs/data-structures/base/iterable-base.js +8 -12
  37. package/dist/mjs/data-structures/binary-tree/binary-tree.js +19 -19
  38. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
  39. package/dist/mjs/data-structures/binary-tree/rb-tree.js +412 -386
  40. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  41. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +84 -76
  42. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  43. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
  44. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
  45. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +16 -86
  46. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
  47. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +33 -79
  48. package/dist/mjs/data-structures/queue/deque.d.ts +0 -53
  49. package/dist/mjs/data-structures/queue/deque.js +0 -61
  50. package/dist/mjs/data-structures/queue/queue.d.ts +0 -70
  51. package/dist/mjs/data-structures/queue/queue.js +0 -86
  52. package/dist/umd/data-structure-typed.js +539 -756
  53. package/dist/umd/data-structure-typed.min.js +2 -2
  54. package/dist/umd/data-structure-typed.min.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/data-structures/base/iterable-base.ts +14 -10
  57. package/src/data-structures/binary-tree/binary-tree.ts +19 -19
  58. package/src/data-structures/binary-tree/rb-tree.ts +437 -395
  59. package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
  60. package/src/data-structures/graph/abstract-graph.ts +4 -0
  61. package/src/data-structures/heap/heap.ts +1 -1
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +16 -94
  63. package/src/data-structures/linked-list/singly-linked-list.ts +35 -87
  64. package/src/data-structures/queue/deque.ts +0 -67
  65. package/src/data-structures/queue/queue.ts +0 -98
  66. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +3 -3
  67. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
  68. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +26 -16
  69. package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
  70. package/test/performance/data-structures/heap/heap.test.ts +14 -14
  71. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +11 -6
  72. package/test/performance/data-structures/queue/deque.test.ts +8 -8
  73. package/test/performance/data-structures/queue/queue.test.ts +5 -12
  74. package/test/performance/reportor.ts +43 -1
  75. package/test/unit/data-structures/binary-tree/overall.test.ts +23 -21
  76. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +168 -105
  77. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +311 -192
  78. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
  79. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +10 -10
  80. package/test/unit/data-structures/linked-list/skip-list.test.ts +4 -4
  81. package/test/unit/data-structures/queue/deque.test.ts +26 -26
  82. package/test/unit/data-structures/queue/queue.test.ts +20 -20
@@ -73,6 +73,22 @@ export class SinglyLinkedList extends IterableElementBase {
73
73
  get tail() {
74
74
  return this._tail;
75
75
  }
76
+ /**
77
+ * The above function returns the value of the first element in a linked list, or undefined if the
78
+ * list is empty.
79
+ * @returns The value of the first node in the linked list, or undefined if the linked list is empty.
80
+ */
81
+ get first() {
82
+ return this.head?.value;
83
+ }
84
+ /**
85
+ * The function returns the value of the last element in a linked list, or undefined if the list is
86
+ * empty.
87
+ * @returns The value of the last node in the linked list, or undefined if the linked list is empty.
88
+ */
89
+ get last() {
90
+ return this.tail?.value;
91
+ }
76
92
  _size = 0;
77
93
  /**
78
94
  * The function returns the size of an object.
@@ -106,19 +122,18 @@ export class SinglyLinkedList extends IterableElementBase {
106
122
  /**
107
123
  * Time Complexity: O(1)
108
124
  * Space Complexity: O(1)
109
- * Constant time, as it involves basic pointer adjustments.
110
- * Constant space, as it only creates a new node.
111
125
  */
112
126
  /**
113
127
  * Time Complexity: O(1)
114
128
  * Space Complexity: O(1)
115
129
  *
116
- * The `push` function adds a new node with the given value to the end of a singly linked list.
117
- * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
118
- * any type (E) as specified in the generic type declaration of the class or function.
130
+ * The push function adds a new element to the end of a singly linked list.
131
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
132
+ * add to the linked list.
133
+ * @returns The `push` method is returning a boolean value, `true`.
119
134
  */
120
- push(value) {
121
- const newNode = new SinglyLinkedListNode(value);
135
+ push(element) {
136
+ const newNode = new SinglyLinkedListNode(element);
122
137
  if (!this.head) {
123
138
  this._head = newNode;
124
139
  this._tail = newNode;
@@ -130,21 +145,6 @@ export class SinglyLinkedList extends IterableElementBase {
130
145
  this._size++;
131
146
  return true;
132
147
  }
133
- /**
134
- * Time Complexity: O(1)
135
- * Space Complexity: O(1)
136
- */
137
- /**
138
- * Time Complexity: O(1)
139
- * Space Complexity: O(1)
140
- *
141
- * The `push` function adds a new node with the given value to the end of a singly linked list.
142
- * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
143
- * any type (E) as specified in the generic type declaration of the class or function.
144
- */
145
- addLast(value) {
146
- return this.push(value);
147
- }
148
148
  /**
149
149
  * Time Complexity: O(n)
150
150
  * Space Complexity: O(1)
@@ -154,10 +154,9 @@ export class SinglyLinkedList extends IterableElementBase {
154
154
  * Time Complexity: O(n)
155
155
  * Space Complexity: O(1)
156
156
  *
157
- * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
158
- * pointers accordingly.
159
- * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
160
- * the linked list is empty, it returns `undefined`.
157
+ * The `pop` function removes and returns the value of the last element in a linked list.
158
+ * @returns The method is returning the value of the element that is being popped from the end of the
159
+ * list.
161
160
  */
162
161
  pop() {
163
162
  if (!this.head)
@@ -179,22 +178,6 @@ export class SinglyLinkedList extends IterableElementBase {
179
178
  this._size--;
180
179
  return value;
181
180
  }
182
- /**
183
- * Time Complexity: O(n)
184
- * Space Complexity: O(1)
185
- */
186
- /**
187
- * Time Complexity: O(n)
188
- * Space Complexity: O(1)
189
- *
190
- * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
191
- * pointers accordingly.
192
- * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
193
- * the linked list is empty, it returns `undefined`.
194
- */
195
- pollLast() {
196
- return this.pop();
197
- }
198
181
  /**
199
182
  * Time Complexity: O(1)
200
183
  * Space Complexity: O(1)
@@ -203,8 +186,8 @@ export class SinglyLinkedList extends IterableElementBase {
203
186
  * Time Complexity: O(1)
204
187
  * Space Complexity: O(1)
205
188
  *
206
- * The `shift()` function removes and returns the value of the first node in a linked list.
207
- * @returns The value of the node that is being removed from the beginning of the linked list.
189
+ * The `shift()` function removes and returns the value of the first element in a linked list.
190
+ * @returns The value of the removed node.
208
191
  */
209
192
  shift() {
210
193
  if (!this.head)
@@ -222,26 +205,13 @@ export class SinglyLinkedList extends IterableElementBase {
222
205
  * Time Complexity: O(1)
223
206
  * Space Complexity: O(1)
224
207
  *
225
- * The `pollFirst()` function removes and returns the value of the first node in a linked list.
226
- * @returns The value of the node that is being removed from the beginning of the linked list.
227
- */
228
- pollFirst() {
229
- return this.shift();
230
- }
231
- /**
232
- * Time Complexity: O(1)
233
- * Space Complexity: O(1)
234
- */
235
- /**
236
- * Time Complexity: O(1)
237
- * Space Complexity: O(1)
238
- *
239
- * The unshift function adds a new node with the given value to the beginning of a singly linked list.
240
- * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
241
- * linked list.
208
+ * The unshift function adds a new element to the beginning of a singly linked list.
209
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
210
+ * add to the beginning of the singly linked list.
211
+ * @returns The `unshift` method is returning a boolean value, `true`.
242
212
  */
243
- unshift(value) {
244
- const newNode = new SinglyLinkedListNode(value);
213
+ unshift(element) {
214
+ const newNode = new SinglyLinkedListNode(element);
245
215
  if (!this.head) {
246
216
  this._head = newNode;
247
217
  this._tail = newNode;
@@ -253,25 +223,9 @@ export class SinglyLinkedList extends IterableElementBase {
253
223
  this._size++;
254
224
  return true;
255
225
  }
256
- /**
257
- * Time Complexity: O(1)
258
- * Space Complexity: O(1)
259
- */
260
- /**
261
- * Time Complexity: O(1)
262
- * Space Complexity: O(1)
263
- *
264
- * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
265
- * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
266
- * linked list.
267
- */
268
- addFirst(value) {
269
- return this.unshift(value);
270
- }
271
226
  /**
272
227
  * Time Complexity: O(n)
273
228
  * Space Complexity: O(1)
274
- * Linear time, where n is the index, as it may need to traverse the list to find the desired node.
275
229
  */
276
230
  /**
277
231
  * Time Complexity: O(n)
@@ -432,59 +432,6 @@ export declare class Deque<E> extends IterableElementBase<E> {
432
432
  * @returns a new Deque object with the mapped values.
433
433
  */
434
434
  map<T>(callback: ElementCallback<E, T>, thisArg?: any): Deque<T>;
435
- /**
436
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
437
- * Space Complexity: O(n) - Due to potential resizing.
438
- */
439
- /**
440
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
441
- * Space Complexity: O(n) - Due to potential resizing.
442
- *
443
- * The addLast function adds an element to the end of an array.
444
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
445
- * data structure.
446
- */
447
- addLast(element: E): boolean;
448
- /**
449
- * Time Complexity: O(1)
450
- * Space Complexity: O(1)
451
- */
452
- /**
453
- * Time Complexity: O(1)
454
- * Space Complexity: O(1)
455
- *
456
- * The function "pollLast" removes and returns the last element of an array.
457
- * @returns The last element of the array is being returned.
458
- */
459
- pollLast(): E | undefined;
460
- /**
461
- * Time Complexity: O(1)
462
- * Space Complexity: O(1)
463
- * /
464
-
465
- /**
466
- * Time Complexity: O(1)
467
- * Space Complexity: O(1)
468
- *
469
- * The "addFirst" function adds an element to the beginning of an array.
470
- * @param {E} element - The parameter "element" represents the element that you want to add to the
471
- * beginning of the data structure.
472
- */
473
- addFirst(element: E): boolean;
474
- /**
475
- * Time Complexity: O(1)
476
- * Space Complexity: O(1)
477
- * /
478
-
479
- /**
480
- * Time Complexity: O(1)
481
- * Space Complexity: O(1)
482
- *
483
- * The function "pollFirst" removes and returns the first element of an array.
484
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
485
- * from the beginning. If the array is empty, it will return `undefined`.
486
- */
487
- pollFirst(): E | undefined;
488
435
  /**
489
436
  * Time Complexity: O(n)
490
437
  * Space Complexity: O(1)
@@ -764,67 +764,6 @@ export class Deque extends IterableElementBase {
764
764
  }
765
765
  return newDeque;
766
766
  }
767
- /**
768
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
769
- * Space Complexity: O(n) - Due to potential resizing.
770
- */
771
- /**
772
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
773
- * Space Complexity: O(n) - Due to potential resizing.
774
- *
775
- * The addLast function adds an element to the end of an array.
776
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
777
- * data structure.
778
- */
779
- addLast(element) {
780
- return this.push(element);
781
- }
782
- /**
783
- * Time Complexity: O(1)
784
- * Space Complexity: O(1)
785
- */
786
- /**
787
- * Time Complexity: O(1)
788
- * Space Complexity: O(1)
789
- *
790
- * The function "pollLast" removes and returns the last element of an array.
791
- * @returns The last element of the array is being returned.
792
- */
793
- pollLast() {
794
- return this.pop();
795
- }
796
- /**
797
- * Time Complexity: O(1)
798
- * Space Complexity: O(1)
799
- * /
800
-
801
- /**
802
- * Time Complexity: O(1)
803
- * Space Complexity: O(1)
804
- *
805
- * The "addFirst" function adds an element to the beginning of an array.
806
- * @param {E} element - The parameter "element" represents the element that you want to add to the
807
- * beginning of the data structure.
808
- */
809
- addFirst(element) {
810
- return this.unshift(element);
811
- }
812
- /**
813
- * Time Complexity: O(1)
814
- * Space Complexity: O(1)
815
- * /
816
-
817
- /**
818
- * Time Complexity: O(1)
819
- * Space Complexity: O(1)
820
- *
821
- * The function "pollFirst" removes and returns the first element of an array.
822
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
823
- * from the beginning. If the array is empty, it will return `undefined`.
824
- */
825
- pollFirst() {
826
- return this.shift();
827
- }
828
767
  /**
829
768
  * Time Complexity: O(n)
830
769
  * Space Complexity: O(1)
@@ -120,56 +120,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
120
120
  * @return A boolean value
121
121
  */
122
122
  deleteAt(index: number): boolean;
123
- /**
124
- * Time Complexity: O(1)
125
- * Space Complexity: O(1)
126
- */
127
- /**
128
- * Time Complexity: O(1)
129
- * Space Complexity: O(1)
130
- *
131
- * The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
132
- * @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
133
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
134
- */
135
- peek(): E | undefined;
136
- /**
137
- * Time Complexity: O(1)
138
- * Space Complexity: O(1)
139
- */
140
- /**
141
- * Time Complexity: O(1)
142
- * Space Complexity: O(1)
143
- *
144
- * The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
145
- * @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
146
- * array is empty, it returns `undefined`.
147
- */
148
- peekLast(): E | undefined;
149
- /**
150
- * Time Complexity: O(1)
151
- * Space Complexity: O(1)
152
- */
153
- /**
154
- * Time Complexity: O(1)
155
- * Space Complexity: O(1)
156
- *
157
- * The enqueue function adds a value to the end of a queue.
158
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
159
- */
160
- enqueue(value: E): boolean;
161
- /**
162
- * Time Complexity: O(1)
163
- * Space Complexity: O(1)
164
- */
165
- /**
166
- * Time Complexity: O(1)
167
- * Space Complexity: O(1)
168
- *
169
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
170
- * @returns The method is returning a value of type E or undefined.
171
- */
172
- dequeue(): E | undefined;
173
123
  /**
174
124
  * Time Complexity: O(1)
175
125
  * Space Complexity: O(1)
@@ -288,26 +238,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
288
238
  * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
289
239
  */
290
240
  export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
291
- /**
292
- * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
293
- * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
294
- */
295
- get first(): E | undefined;
296
- /**
297
- * The enqueue function adds a value to the end of an array.
298
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
299
- */
300
- enqueue(value: E): boolean;
301
- /**
302
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
303
- * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
304
- */
305
- dequeue(): E | undefined;
306
- /**
307
- * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
308
- * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
309
- */
310
- peek(): E | undefined;
311
241
  /**
312
242
  * Time Complexity: O(n)
313
243
  * Space Complexity: O(n)
@@ -153,64 +153,6 @@ export class Queue extends IterableElementBase {
153
153
  const spliced = this.elements.splice(index, 1);
154
154
  return spliced.length === 1;
155
155
  }
156
- /**
157
- * Time Complexity: O(1)
158
- * Space Complexity: O(1)
159
- */
160
- /**
161
- * Time Complexity: O(1)
162
- * Space Complexity: O(1)
163
- *
164
- * The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
165
- * @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
166
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
167
- */
168
- peek() {
169
- return this.first;
170
- }
171
- /**
172
- * Time Complexity: O(1)
173
- * Space Complexity: O(1)
174
- */
175
- /**
176
- * Time Complexity: O(1)
177
- * Space Complexity: O(1)
178
- *
179
- * The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
180
- * @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
181
- * array is empty, it returns `undefined`.
182
- */
183
- peekLast() {
184
- return this.last;
185
- }
186
- /**
187
- * Time Complexity: O(1)
188
- * Space Complexity: O(1)
189
- */
190
- /**
191
- * Time Complexity: O(1)
192
- * Space Complexity: O(1)
193
- *
194
- * The enqueue function adds a value to the end of a queue.
195
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
196
- */
197
- enqueue(value) {
198
- return this.push(value);
199
- }
200
- /**
201
- * Time Complexity: O(1)
202
- * Space Complexity: O(1)
203
- */
204
- /**
205
- * Time Complexity: O(1)
206
- * Space Complexity: O(1)
207
- *
208
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
209
- * @returns The method is returning a value of type E or undefined.
210
- */
211
- dequeue() {
212
- return this.shift();
213
- }
214
156
  /**
215
157
  * Time Complexity: O(1)
216
158
  * Space Complexity: O(1)
@@ -362,34 +304,6 @@ export class Queue extends IterableElementBase {
362
304
  * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
363
305
  */
364
306
  export class LinkedListQueue extends SinglyLinkedList {
365
- /**
366
- * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
367
- * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
368
- */
369
- get first() {
370
- return this.head?.value;
371
- }
372
- /**
373
- * The enqueue function adds a value to the end of an array.
374
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
375
- */
376
- enqueue(value) {
377
- return this.push(value);
378
- }
379
- /**
380
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
381
- * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
382
- */
383
- dequeue() {
384
- return this.shift();
385
- }
386
- /**
387
- * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
388
- * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
389
- */
390
- peek() {
391
- return this.first;
392
- }
393
307
  /**
394
308
  * Time Complexity: O(n)
395
309
  * Space Complexity: O(n)