linked-list-typed 1.49.1 → 1.49.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 (40) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +11 -0
  2. package/dist/data-structures/base/iterable-base.js +21 -0
  3. package/dist/data-structures/graph/abstract-graph.d.ts +7 -7
  4. package/dist/data-structures/graph/abstract-graph.js +43 -12
  5. package/dist/data-structures/graph/directed-graph.d.ts +2 -2
  6. package/dist/data-structures/graph/directed-graph.js +2 -2
  7. package/dist/data-structures/graph/undirected-graph.d.ts +1 -1
  8. package/dist/data-structures/graph/undirected-graph.js +1 -1
  9. package/dist/data-structures/hash/hash-map.d.ts +9 -9
  10. package/dist/data-structures/hash/hash-map.js +16 -15
  11. package/dist/data-structures/heap/heap.d.ts +6 -35
  12. package/dist/data-structures/heap/heap.js +10 -42
  13. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
  14. package/dist/data-structures/linked-list/doubly-linked-list.js +143 -146
  15. package/dist/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  16. package/dist/data-structures/linked-list/singly-linked-list.js +42 -42
  17. package/dist/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  18. package/dist/data-structures/linked-list/skip-linked-list.js +36 -36
  19. package/dist/data-structures/queue/deque.d.ts +70 -75
  20. package/dist/data-structures/queue/deque.js +100 -110
  21. package/dist/data-structures/queue/queue.d.ts +37 -38
  22. package/dist/data-structures/queue/queue.js +46 -49
  23. package/dist/data-structures/stack/stack.d.ts +2 -3
  24. package/dist/data-structures/stack/stack.js +2 -5
  25. package/dist/data-structures/trie/trie.d.ts +1 -2
  26. package/dist/data-structures/trie/trie.js +2 -5
  27. package/package.json +2 -2
  28. package/src/data-structures/base/iterable-base.ts +24 -0
  29. package/src/data-structures/graph/abstract-graph.ts +55 -14
  30. package/src/data-structures/graph/directed-graph.ts +3 -2
  31. package/src/data-structures/graph/undirected-graph.ts +1 -1
  32. package/src/data-structures/hash/hash-map.ts +27 -28
  33. package/src/data-structures/heap/heap.ts +19 -57
  34. package/src/data-structures/linked-list/doubly-linked-list.ts +157 -161
  35. package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
  36. package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
  37. package/src/data-structures/queue/deque.ts +122 -135
  38. package/src/data-structures/queue/queue.ts +54 -58
  39. package/src/data-structures/stack/stack.ts +4 -8
  40. package/src/data-structures/trie/trie.ts +5 -9
@@ -42,68 +42,6 @@ export declare class Deque<E> extends IterableElementBase<E> {
42
42
  */
43
43
  get first(): E | undefined;
44
44
  get last(): E | undefined;
45
- /**
46
- * Time Complexity: O(1) - Removes the last element.
47
- * Space Complexity: O(1) - Operates in-place.
48
- */
49
- isEmpty(): boolean;
50
- /**
51
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
52
- * Space Complexity: O(n) - Due to potential resizing.
53
- */
54
- /**
55
- * Time Complexity: O(1)
56
- * Space Complexity: O(n) - In worst case, resizing doubles the array size.
57
- *
58
- * The addLast function adds an element to the end of an array.
59
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
60
- * data structure.
61
- */
62
- addLast(element: E): void;
63
- /**
64
- * Time Complexity: O(1) - Removes the first element.
65
- * Space Complexity: O(1) - In-place operation.
66
- */
67
- /**
68
- * Time Complexity: O(1) - Removes the last element.
69
- * Space Complexity: O(1) - Operates in-place.
70
- *
71
- * The function "pollLast" removes and returns the last element of an array.
72
- * @returns The last element of the array is being returned.
73
- */
74
- pollLast(): E | undefined;
75
- /**
76
- * Time Complexity: O(1).
77
- * Space Complexity: O(n) - Due to potential resizing.
78
- *
79
- * The "addFirst" function adds an element to the beginning of an array.
80
- * @param {E} element - The parameter "element" represents the element that you want to add to the
81
- * beginning of the data structure.
82
- */
83
- addFirst(element: E): void;
84
- /**
85
- * Time Complexity: O(1) - Removes the first element.
86
- * Space Complexity: O(1) - In-place operation.
87
- *
88
- * The function "pollFirst" removes and returns the first element of an array.
89
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
90
- * from the beginning. If the array is empty, it will return `undefined`.
91
- */
92
- pollFirst(): E | undefined;
93
- /**
94
- * The clear() function resets the state of the object by initializing all variables to their default
95
- * values.
96
- */
97
- clear(): void;
98
- /**
99
- * The below function is a generator that yields elements from a collection one by one.
100
- */
101
- begin(): Generator<E>;
102
- /**
103
- * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
104
- * the last element.
105
- */
106
- reverseBegin(): Generator<E>;
107
45
  /**
108
46
  * Time Complexity - Amortized O(1) (possible reallocation)
109
47
  * Space Complexity - O(n) (due to potential resizing).
@@ -117,7 +55,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
117
55
  * structure.
118
56
  * @returns The size of the data structure after the element has been pushed.
119
57
  */
120
- push(element: E): number;
58
+ push(element: E): boolean;
121
59
  /**
122
60
  * Time Complexity: O(1)
123
61
  * Space Complexity: O(1)
@@ -145,7 +83,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
145
83
  * beginning of the data structure.
146
84
  * @returns The size of the data structure after the element has been added.
147
85
  */
148
- unshift(element: E): number;
86
+ unshift(element: E): boolean;
149
87
  /**
150
88
  * Time Complexity: O(1)
151
89
  * Space Complexity: O(1)
@@ -160,6 +98,25 @@ export declare class Deque<E> extends IterableElementBase<E> {
160
98
  * returned.
161
99
  */
162
100
  shift(): E | undefined;
101
+ /**
102
+ * Time Complexity: O(1) - Removes the last element.
103
+ * Space Complexity: O(1) - Operates in-place.
104
+ */
105
+ isEmpty(): boolean;
106
+ /**
107
+ * The clear() function resets the state of the object by initializing all variables to their default
108
+ * values.
109
+ */
110
+ clear(): void;
111
+ /**
112
+ * The below function is a generator that yields elements from a collection one by one.
113
+ */
114
+ begin(): Generator<E>;
115
+ /**
116
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
117
+ * the last element.
118
+ */
119
+ reverseBegin(): Generator<E>;
163
120
  /**
164
121
  * Time Complexity: O(1)
165
122
  * Space Complexity: O(1)
@@ -189,7 +146,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
189
146
  * @param {E} element - The `element` parameter is the value that you want to set at the specified
190
147
  * position in the data structure.
191
148
  */
192
- setAt(pos: number, element: E): void;
149
+ setAt(pos: number, element: E): boolean;
193
150
  /**
194
151
  * Time Complexity: O(n)
195
152
  * Space Complexity: O(n)
@@ -198,7 +155,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
198
155
  * Time Complexity: O(n)
199
156
  * Space Complexity: O(n)
200
157
  *
201
- * The `insertAt` function inserts one or more elements at a specified position in an array-like data
158
+ * The `addAt` function inserts one or more elements at a specified position in an array-like data
202
159
  * structure.
203
160
  * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
204
161
  * be inserted. It is of type `number`.
@@ -209,7 +166,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
209
166
  * will be inserted once. However, you can provide a different value for `num` if you want
210
167
  * @returns The size of the array after the insertion is being returned.
211
168
  */
212
- insertAt(pos: number, element: E, num?: number): number;
169
+ addAt(pos: number, element: E, num?: number): boolean;
213
170
  /**
214
171
  * Time Complexity: O(1)
215
172
  * Space Complexity: O(1)
@@ -240,7 +197,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
240
197
  * the index of the element to be deleted.
241
198
  * @returns The size of the data structure after the deletion operation is performed.
242
199
  */
243
- deleteAt(pos: number): number;
200
+ deleteAt(pos: number): boolean;
244
201
  /**
245
202
  * Time Complexity: O(n)
246
203
  * Space Complexity: O(1)
@@ -255,7 +212,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
255
212
  * the data structure.
256
213
  * @returns The size of the data structure after the element has been deleted.
257
214
  */
258
- delete(element: E): number;
215
+ delete(element: E): boolean;
259
216
  /**
260
217
  * Time Complexity: O(n)
261
218
  * Space Complexity: O(1)
@@ -282,7 +239,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
282
239
  * the number of unique elements.
283
240
  * @returns The size of the modified array is being returned.
284
241
  */
285
- unique(): number;
242
+ unique(): this;
286
243
  /**
287
244
  * Time Complexity: O(n log n)
288
245
  * Space Complexity: O(n)
@@ -295,7 +252,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
295
252
  * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
296
253
  * `y` of type `E` and returns a number. The comparator function is used to determine the order of
297
254
  * the elements in the sorted array.
298
- * @returns The method is returning the sorted instance of the object on which the method is called.
255
+ * @returns Deque<E>
299
256
  */
300
257
  sort(comparator?: (x: E, y: E) => number): this;
301
258
  /**
@@ -396,10 +353,48 @@ export declare class Deque<E> extends IterableElementBase<E> {
396
353
  */
397
354
  map<T>(callback: ElementCallback<E, T>, thisArg?: any): Deque<T>;
398
355
  /**
399
- * Time Complexity: O(n)
400
- * Space Complexity: O(n)
356
+ * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
357
+ * Space Complexity: O(n) - Due to potential resizing.
358
+ */
359
+ /**
360
+ * Time Complexity: O(1)
361
+ * Space Complexity: O(n) - In worst case, resizing doubles the array size.
362
+ *
363
+ * The addLast function adds an element to the end of an array.
364
+ * @param {E} element - The element parameter represents the element that you want to add to the end of the
365
+ * data structure.
366
+ */
367
+ addLast(element: E): boolean;
368
+ /**
369
+ * Time Complexity: O(1) - Removes the first element.
370
+ * Space Complexity: O(1) - In-place operation.
371
+ */
372
+ /**
373
+ * Time Complexity: O(1) - Removes the last element.
374
+ * Space Complexity: O(1) - Operates in-place.
375
+ *
376
+ * The function "pollLast" removes and returns the last element of an array.
377
+ * @returns The last element of the array is being returned.
378
+ */
379
+ pollLast(): E | undefined;
380
+ /**
381
+ * Time Complexity: O(1).
382
+ * Space Complexity: O(n) - Due to potential resizing.
383
+ *
384
+ * The "addFirst" function adds an element to the beginning of an array.
385
+ * @param {E} element - The parameter "element" represents the element that you want to add to the
386
+ * beginning of the data structure.
401
387
  */
402
- print(): void;
388
+ addFirst(element: E): boolean;
389
+ /**
390
+ * Time Complexity: O(1) - Removes the first element.
391
+ * Space Complexity: O(1) - In-place operation.
392
+ *
393
+ * The function "pollFirst" removes and returns the first element of an array.
394
+ * @returns The method `pollFirst()` is returning the first element of the array after removing it
395
+ * from the beginning. If the array is empty, it will return `undefined`.
396
+ */
397
+ pollFirst(): E | undefined;
403
398
  /**
404
399
  * Time Complexity: O(n)
405
400
  * Space Complexity: O(1)
@@ -407,7 +402,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
407
402
  * The above function is an implementation of the iterator protocol in TypeScript, allowing the
408
403
  * object to be iterated over using a for...of loop.
409
404
  */
410
- protected _getIterator(): Generator<E, void, unknown>;
405
+ protected _getIterator(): IterableIterator<E>;
411
406
  /**
412
407
  * Time Complexity: O(n)
413
408
  * Space Complexity: O(n)
@@ -75,95 +75,6 @@ class Deque extends base_1.IterableElementBase {
75
75
  return;
76
76
  return this._buckets[this._bucketLast][this._lastInBucket];
77
77
  }
78
- /**
79
- * Time Complexity: O(1) - Removes the last element.
80
- * Space Complexity: O(1) - Operates in-place.
81
- */
82
- isEmpty() {
83
- return this.size === 0;
84
- }
85
- /**
86
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
87
- * Space Complexity: O(n) - Due to potential resizing.
88
- */
89
- /**
90
- * Time Complexity: O(1)
91
- * Space Complexity: O(n) - In worst case, resizing doubles the array size.
92
- *
93
- * The addLast function adds an element to the end of an array.
94
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
95
- * data structure.
96
- */
97
- addLast(element) {
98
- this.push(element);
99
- }
100
- /**
101
- * Time Complexity: O(1) - Removes the first element.
102
- * Space Complexity: O(1) - In-place operation.
103
- */
104
- /**
105
- * Time Complexity: O(1) - Removes the last element.
106
- * Space Complexity: O(1) - Operates in-place.
107
- *
108
- * The function "pollLast" removes and returns the last element of an array.
109
- * @returns The last element of the array is being returned.
110
- */
111
- pollLast() {
112
- return this.pop();
113
- }
114
- /**
115
- * Time Complexity: O(1).
116
- * Space Complexity: O(n) - Due to potential resizing.
117
- *
118
- * The "addFirst" function adds an element to the beginning of an array.
119
- * @param {E} element - The parameter "element" represents the element that you want to add to the
120
- * beginning of the data structure.
121
- */
122
- addFirst(element) {
123
- this.unshift(element);
124
- }
125
- /**
126
- * Time Complexity: O(1) - Removes the first element.
127
- * Space Complexity: O(1) - In-place operation.
128
- *
129
- * The function "pollFirst" removes and returns the first element of an array.
130
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
131
- * from the beginning. If the array is empty, it will return `undefined`.
132
- */
133
- pollFirst() {
134
- return this.shift();
135
- }
136
- /**
137
- * The clear() function resets the state of the object by initializing all variables to their default
138
- * values.
139
- */
140
- clear() {
141
- this._buckets = [new Array(this._bucketSize)];
142
- this._bucketCount = 1;
143
- this._bucketFirst = this._bucketLast = this._size = 0;
144
- this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
145
- }
146
- /**
147
- * The below function is a generator that yields elements from a collection one by one.
148
- */
149
- *begin() {
150
- let index = 0;
151
- while (index < this.size) {
152
- yield this.getAt(index);
153
- index++;
154
- }
155
- }
156
- /**
157
- * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
158
- * the last element.
159
- */
160
- *reverseBegin() {
161
- let index = this.size - 1;
162
- while (index >= 0) {
163
- yield this.getAt(index);
164
- index--;
165
- }
166
- }
167
78
  /**
168
79
  * Time Complexity - Amortized O(1) (possible reallocation)
169
80
  * Space Complexity - O(n) (due to potential resizing).
@@ -196,7 +107,7 @@ class Deque extends base_1.IterableElementBase {
196
107
  }
197
108
  this._size += 1;
198
109
  this._buckets[this._bucketLast][this._lastInBucket] = element;
199
- return this.size;
110
+ return true;
200
111
  }
201
112
  /**
202
113
  * Time Complexity: O(1)
@@ -263,7 +174,7 @@ class Deque extends base_1.IterableElementBase {
263
174
  }
264
175
  this._size += 1;
265
176
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
266
- return this.size;
177
+ return true;
267
178
  }
268
179
  /**
269
180
  * Time Complexity: O(1)
@@ -298,6 +209,44 @@ class Deque extends base_1.IterableElementBase {
298
209
  this._size -= 1;
299
210
  return element;
300
211
  }
212
+ /**
213
+ * Time Complexity: O(1) - Removes the last element.
214
+ * Space Complexity: O(1) - Operates in-place.
215
+ */
216
+ isEmpty() {
217
+ return this.size === 0;
218
+ }
219
+ /**
220
+ * The clear() function resets the state of the object by initializing all variables to their default
221
+ * values.
222
+ */
223
+ clear() {
224
+ this._buckets = [new Array(this._bucketSize)];
225
+ this._bucketCount = 1;
226
+ this._bucketFirst = this._bucketLast = this._size = 0;
227
+ this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
228
+ }
229
+ /**
230
+ * The below function is a generator that yields elements from a collection one by one.
231
+ */
232
+ *begin() {
233
+ let index = 0;
234
+ while (index < this.size) {
235
+ yield this.getAt(index);
236
+ index++;
237
+ }
238
+ }
239
+ /**
240
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
241
+ * the last element.
242
+ */
243
+ *reverseBegin() {
244
+ let index = this.size - 1;
245
+ while (index >= 0) {
246
+ yield this.getAt(index);
247
+ index--;
248
+ }
249
+ }
301
250
  /**
302
251
  * Time Complexity: O(1)
303
252
  * Space Complexity: O(1)
@@ -335,6 +284,7 @@ class Deque extends base_1.IterableElementBase {
335
284
  (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
336
285
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
337
286
  this._buckets[bucketIndex][indexInBucket] = element;
287
+ return true;
338
288
  }
339
289
  /**
340
290
  * Time Complexity: O(n)
@@ -344,7 +294,7 @@ class Deque extends base_1.IterableElementBase {
344
294
  * Time Complexity: O(n)
345
295
  * Space Complexity: O(n)
346
296
  *
347
- * The `insertAt` function inserts one or more elements at a specified position in an array-like data
297
+ * The `addAt` function inserts one or more elements at a specified position in an array-like data
348
298
  * structure.
349
299
  * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
350
300
  * be inserted. It is of type `number`.
@@ -355,7 +305,7 @@ class Deque extends base_1.IterableElementBase {
355
305
  * will be inserted once. However, you can provide a different value for `num` if you want
356
306
  * @returns The size of the array after the insertion is being returned.
357
307
  */
358
- insertAt(pos, element, num = 1) {
308
+ addAt(pos, element, num = 1) {
359
309
  const length = this.size;
360
310
  (0, utils_1.rangeCheck)(pos, 0, length);
361
311
  if (pos === 0) {
@@ -377,7 +327,7 @@ class Deque extends base_1.IterableElementBase {
377
327
  for (let i = 0; i < arr.length; ++i)
378
328
  this.push(arr[i]);
379
329
  }
380
- return this.size;
330
+ return true;
381
331
  }
382
332
  /**
383
333
  * Time Complexity: O(1)
@@ -436,7 +386,7 @@ class Deque extends base_1.IterableElementBase {
436
386
  }
437
387
  this.pop();
438
388
  }
439
- return this.size;
389
+ return true;
440
390
  }
441
391
  /**
442
392
  * Time Complexity: O(n)
@@ -455,7 +405,7 @@ class Deque extends base_1.IterableElementBase {
455
405
  delete(element) {
456
406
  const size = this.size;
457
407
  if (size === 0)
458
- return 0;
408
+ return false;
459
409
  let i = 0;
460
410
  let index = 0;
461
411
  while (i < size) {
@@ -467,7 +417,7 @@ class Deque extends base_1.IterableElementBase {
467
417
  i += 1;
468
418
  }
469
419
  this.cut(index - 1);
470
- return this.size;
420
+ return true;
471
421
  }
472
422
  /**
473
423
  * Time Complexity: O(n)
@@ -507,7 +457,7 @@ class Deque extends base_1.IterableElementBase {
507
457
  */
508
458
  unique() {
509
459
  if (this.size <= 1) {
510
- return this.size;
460
+ return this;
511
461
  }
512
462
  let index = 1;
513
463
  let prev = this.getAt(0);
@@ -519,7 +469,7 @@ class Deque extends base_1.IterableElementBase {
519
469
  }
520
470
  }
521
471
  this.cut(index - 1);
522
- return this.size;
472
+ return this;
523
473
  }
524
474
  /**
525
475
  * Time Complexity: O(n log n)
@@ -533,7 +483,7 @@ class Deque extends base_1.IterableElementBase {
533
483
  * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
534
484
  * `y` of type `E` and returns a number. The comparator function is used to determine the order of
535
485
  * the elements in the sorted array.
536
- * @returns The method is returning the sorted instance of the object on which the method is called.
486
+ * @returns Deque<E>
537
487
  */
538
488
  sort(comparator) {
539
489
  const arr = [];
@@ -604,7 +554,7 @@ class Deque extends base_1.IterableElementBase {
604
554
  return element;
605
555
  }
606
556
  }
607
- return undefined;
557
+ return;
608
558
  }
609
559
  /**
610
560
  * Time Complexity: O(n)
@@ -641,11 +591,7 @@ class Deque extends base_1.IterableElementBase {
641
591
  * @returns The `toArray()` method is returning an array of elements of type `E`.
642
592
  */
643
593
  toArray() {
644
- const arr = [];
645
- for (let i = 0; i < this.size; ++i) {
646
- arr.push(this.getAt(i));
647
- }
648
- return arr;
594
+ return [...this];
649
595
  }
650
596
  /**
651
597
  * Time Complexity: O(n)
@@ -705,11 +651,55 @@ class Deque extends base_1.IterableElementBase {
705
651
  return newDeque;
706
652
  }
707
653
  /**
708
- * Time Complexity: O(n)
709
- * Space Complexity: O(n)
654
+ * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
655
+ * Space Complexity: O(n) - Due to potential resizing.
656
+ */
657
+ /**
658
+ * Time Complexity: O(1)
659
+ * Space Complexity: O(n) - In worst case, resizing doubles the array size.
660
+ *
661
+ * The addLast function adds an element to the end of an array.
662
+ * @param {E} element - The element parameter represents the element that you want to add to the end of the
663
+ * data structure.
664
+ */
665
+ addLast(element) {
666
+ return this.push(element);
667
+ }
668
+ /**
669
+ * Time Complexity: O(1) - Removes the first element.
670
+ * Space Complexity: O(1) - In-place operation.
671
+ */
672
+ /**
673
+ * Time Complexity: O(1) - Removes the last element.
674
+ * Space Complexity: O(1) - Operates in-place.
675
+ *
676
+ * The function "pollLast" removes and returns the last element of an array.
677
+ * @returns The last element of the array is being returned.
710
678
  */
711
- print() {
712
- console.log([...this]);
679
+ pollLast() {
680
+ return this.pop();
681
+ }
682
+ /**
683
+ * Time Complexity: O(1).
684
+ * Space Complexity: O(n) - Due to potential resizing.
685
+ *
686
+ * The "addFirst" function adds an element to the beginning of an array.
687
+ * @param {E} element - The parameter "element" represents the element that you want to add to the
688
+ * beginning of the data structure.
689
+ */
690
+ addFirst(element) {
691
+ return this.unshift(element);
692
+ }
693
+ /**
694
+ * Time Complexity: O(1) - Removes the first element.
695
+ * Space Complexity: O(1) - In-place operation.
696
+ *
697
+ * The function "pollFirst" removes and returns the first element of an array.
698
+ * @returns The method `pollFirst()` is returning the first element of the array after removing it
699
+ * from the beginning. If the array is empty, it will return `undefined`.
700
+ */
701
+ pollFirst() {
702
+ return this.shift();
713
703
  }
714
704
  /**
715
705
  * Time Complexity: O(n)