stack-typed 1.49.1 → 1.49.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 (31) 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/hash/hash-map.d.ts +9 -9
  4. package/dist/data-structures/hash/hash-map.js +16 -15
  5. package/dist/data-structures/heap/heap.d.ts +6 -35
  6. package/dist/data-structures/heap/heap.js +10 -42
  7. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +87 -93
  8. package/dist/data-structures/linked-list/doubly-linked-list.js +126 -129
  9. package/dist/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  10. package/dist/data-structures/linked-list/singly-linked-list.js +42 -42
  11. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  12. package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
  13. package/dist/data-structures/queue/deque.d.ts +70 -75
  14. package/dist/data-structures/queue/deque.js +100 -110
  15. package/dist/data-structures/queue/queue.d.ts +13 -14
  16. package/dist/data-structures/queue/queue.js +15 -18
  17. package/dist/data-structures/stack/stack.d.ts +2 -3
  18. package/dist/data-structures/stack/stack.js +2 -5
  19. package/dist/data-structures/trie/trie.d.ts +1 -2
  20. package/dist/data-structures/trie/trie.js +2 -5
  21. package/package.json +1 -1
  22. package/src/data-structures/base/iterable-base.ts +24 -0
  23. package/src/data-structures/hash/hash-map.ts +27 -28
  24. package/src/data-structures/heap/heap.ts +19 -57
  25. package/src/data-structures/linked-list/doubly-linked-list.ts +138 -142
  26. package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
  27. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  28. package/src/data-structures/queue/deque.ts +122 -135
  29. package/src/data-structures/queue/queue.ts +19 -23
  30. package/src/data-structures/stack/stack.ts +4 -8
  31. package/src/data-structures/trie/trie.ts +5 -9
@@ -22,7 +22,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
22
22
  super();
23
23
  this._head = undefined;
24
24
  this._tail = undefined;
25
- this._length = 0;
25
+ this._size = 0;
26
26
  if (elements) {
27
27
  for (const el of elements)
28
28
  this.push(el);
@@ -34,8 +34,8 @@ class SinglyLinkedList extends base_1.IterableElementBase {
34
34
  get tail() {
35
35
  return this._tail;
36
36
  }
37
- get length() {
38
- return this._length;
37
+ get size() {
38
+ return this._size;
39
39
  }
40
40
  /**
41
41
  * 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.
@@ -79,7 +79,8 @@ class SinglyLinkedList extends base_1.IterableElementBase {
79
79
  this.tail.next = newNode;
80
80
  this._tail = newNode;
81
81
  }
82
- this._length++;
82
+ this._size++;
83
+ return true;
83
84
  }
84
85
  /**
85
86
  * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
@@ -94,7 +95,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
94
95
  * any type (E) as specified in the generic type declaration of the class or function.
95
96
  */
96
97
  addLast(value) {
97
- this.push(value);
98
+ return this.push(value);
98
99
  }
99
100
  /**
100
101
  * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
@@ -116,7 +117,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
116
117
  const value = this.head.value;
117
118
  this._head = undefined;
118
119
  this._tail = undefined;
119
- this._length--;
120
+ this._size--;
120
121
  return value;
121
122
  }
122
123
  let current = this.head;
@@ -126,7 +127,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
126
127
  const value = this.tail.value;
127
128
  current.next = undefined;
128
129
  this._tail = current;
129
- this._length--;
130
+ this._size--;
130
131
  return value;
131
132
  }
132
133
  /**
@@ -161,7 +162,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
161
162
  return undefined;
162
163
  const removedNode = this.head;
163
164
  this._head = this.head.next;
164
- this._length--;
165
+ this._size--;
165
166
  return removedNode.value;
166
167
  }
167
168
  /**
@@ -200,7 +201,8 @@ class SinglyLinkedList extends base_1.IterableElementBase {
200
201
  newNode.next = this.head;
201
202
  this._head = newNode;
202
203
  }
203
- this._length++;
204
+ this._size++;
205
+ return true;
204
206
  }
205
207
  /**
206
208
  * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
@@ -215,7 +217,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
215
217
  * linked list.
216
218
  */
217
219
  addFirst(value) {
218
- this.unshift(value);
220
+ return this.unshift(value);
219
221
  }
220
222
  /**
221
223
  * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
@@ -232,7 +234,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
232
234
  * `undefined` if the index is out of bounds.
233
235
  */
234
236
  getAt(index) {
235
- if (index < 0 || index >= this.length)
237
+ if (index < 0 || index >= this.size)
236
238
  return undefined;
237
239
  let current = this.head;
238
240
  for (let i = 0; i < index; i++) {
@@ -276,17 +278,21 @@ class SinglyLinkedList extends base_1.IterableElementBase {
276
278
  * bounds.
277
279
  */
278
280
  deleteAt(index) {
279
- if (index < 0 || index >= this.length)
280
- return undefined;
281
- if (index === 0)
282
- return this.shift();
283
- if (index === this.length - 1)
284
- return this.pop();
281
+ if (index < 0 || index >= this.size)
282
+ return false;
283
+ if (index === 0) {
284
+ this.shift();
285
+ return true;
286
+ }
287
+ if (index === this.size - 1) {
288
+ this.pop();
289
+ return true;
290
+ }
285
291
  const prevNode = this.getNodeAt(index - 1);
286
292
  const removedNode = prevNode.next;
287
293
  prevNode.next = removedNode.next;
288
- this._length--;
289
- return removedNode.value;
294
+ this._size--;
295
+ return true;
290
296
  }
291
297
  /**
292
298
  * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
@@ -327,7 +333,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
327
333
  this._tail = prev;
328
334
  }
329
335
  }
330
- this._length--;
336
+ this._size--;
331
337
  return true;
332
338
  }
333
339
  prev = current;
@@ -343,7 +349,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
343
349
  * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
344
350
  * Space Complexity: O(1) - Constant space.
345
351
  *
346
- * The `insertAt` function inserts a value at a specified index in a singly linked list.
352
+ * The `addAt` function inserts a value at a specified index in a singly linked list.
347
353
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
348
354
  * linked list. It is of type number.
349
355
  * @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
@@ -351,14 +357,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
351
357
  * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
352
358
  * if the index is out of bounds.
353
359
  */
354
- insertAt(index, value) {
355
- if (index < 0 || index > this.length)
360
+ addAt(index, value) {
361
+ if (index < 0 || index > this.size)
356
362
  return false;
357
363
  if (index === 0) {
358
364
  this.unshift(value);
359
365
  return true;
360
366
  }
361
- if (index === this.length) {
367
+ if (index === this.size) {
362
368
  this.push(value);
363
369
  return true;
364
370
  }
@@ -366,7 +372,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
366
372
  const prevNode = this.getNodeAt(index - 1);
367
373
  newNode.next = prevNode.next;
368
374
  prevNode.next = newNode;
369
- this._length++;
375
+ this._size++;
370
376
  return true;
371
377
  }
372
378
  /**
@@ -375,7 +381,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
375
381
  * @returns A boolean value indicating whether the length of the object is equal to 0.
376
382
  */
377
383
  isEmpty() {
378
- return this.length === 0;
384
+ return this.size === 0;
379
385
  }
380
386
  /**
381
387
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
@@ -383,7 +389,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
383
389
  clear() {
384
390
  this._head = undefined;
385
391
  this._tail = undefined;
386
- this._length = 0;
392
+ this._size = 0;
387
393
  }
388
394
  /**
389
395
  * 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.
@@ -418,7 +424,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
418
424
  */
419
425
  reverse() {
420
426
  if (!this.head || this.head === this.tail)
421
- return;
427
+ return this;
422
428
  let prev = undefined;
423
429
  let current = this.head;
424
430
  let next = undefined;
@@ -429,6 +435,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
429
435
  current = next;
430
436
  }
431
437
  [this._head, this._tail] = [this.tail, this.head];
438
+ return this;
432
439
  }
433
440
  /**
434
441
  * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
@@ -511,14 +518,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
511
518
  * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
512
519
  * Space Complexity: O(1) - Constant space.
513
520
  *
514
- * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
521
+ * The `addBefore` function inserts a new value before an existing value in a singly linked list.
515
522
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
516
523
  * new value before. It can be either the value itself or a node containing the value in the linked list.
517
524
  * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
518
- * @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
525
+ * @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
519
526
  * inserted before the existing value, and `false` otherwise.
520
527
  */
521
- insertBefore(existingValueOrNode, newValue) {
528
+ addBefore(existingValueOrNode, newValue) {
522
529
  if (!this.head)
523
530
  return false;
524
531
  let existingValue;
@@ -538,7 +545,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
538
545
  const newNode = new SinglyLinkedListNode(newValue);
539
546
  newNode.next = current.next;
540
547
  current.next = newNode;
541
- this._length++;
548
+ this._size++;
542
549
  return true;
543
550
  }
544
551
  current = current.next;
@@ -553,14 +560,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
553
560
  * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
554
561
  * Space Complexity: O(1) - Constant space.
555
562
  *
556
- * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
563
+ * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
557
564
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
558
565
  * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
559
566
  * @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
560
567
  * @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
561
568
  * existing value or node, and false if the existing value or node was not found in the linked list.
562
569
  */
563
- insertAfter(existingValueOrNode, newValue) {
570
+ addAfter(existingValueOrNode, newValue) {
564
571
  let existingNode;
565
572
  if (existingValueOrNode instanceof SinglyLinkedListNode) {
566
573
  existingNode = existingValueOrNode;
@@ -575,7 +582,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
575
582
  if (existingNode === this.tail) {
576
583
  this._tail = newNode;
577
584
  }
578
- this._length++;
585
+ this._size++;
579
586
  return true;
580
587
  }
581
588
  return false;
@@ -662,13 +669,6 @@ class SinglyLinkedList extends base_1.IterableElementBase {
662
669
  }
663
670
  return mappedList;
664
671
  }
665
- /**
666
- * Time Complexity: O(n), where n is the number of elements in the linked list.
667
- * Space Complexity: O(n)
668
- */
669
- print() {
670
- console.log([...this]);
671
- }
672
672
  *_getIterator() {
673
673
  let current = this.head;
674
674
  while (current) {
@@ -90,7 +90,7 @@ export declare class SkipList<K, V> {
90
90
  * Get the value of the first element (the smallest element) in the Skip List.
91
91
  * @returns The value of the first element, or undefined if the Skip List is empty.
92
92
  */
93
- getFirst(): V | undefined;
93
+ get first(): V | undefined;
94
94
  /**
95
95
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
96
96
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -102,7 +102,7 @@ export declare class SkipList<K, V> {
102
102
  * Get the value of the last element (the largest element) in the Skip List.
103
103
  * @returns The value of the last element, or undefined if the Skip List is empty.
104
104
  */
105
- getLast(): V | undefined;
105
+ get last(): V | undefined;
106
106
  /**
107
107
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
108
108
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -158,7 +158,7 @@ class SkipList {
158
158
  * Get the value of the first element (the smallest element) in the Skip List.
159
159
  * @returns The value of the first element, or undefined if the Skip List is empty.
160
160
  */
161
- getFirst() {
161
+ get first() {
162
162
  const firstNode = this.head.forward[0];
163
163
  return firstNode ? firstNode.value : undefined;
164
164
  }
@@ -173,7 +173,7 @@ class SkipList {
173
173
  * Get the value of the last element (the largest element) in the Skip List.
174
174
  * @returns The value of the last element, or undefined if the Skip List is empty.
175
175
  */
176
- getLast() {
176
+ get last() {
177
177
  let current = this.head;
178
178
  for (let i = this.level - 1; i >= 0; i--) {
179
179
  while (current.forward[i]) {
@@ -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)