min-heap-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 (28) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +10 -8
  2. package/dist/data-structures/base/iterable-base.js +8 -12
  3. package/dist/data-structures/binary-tree/binary-tree.js +19 -19
  4. package/dist/data-structures/binary-tree/rb-tree.d.ts +158 -135
  5. package/dist/data-structures/binary-tree/rb-tree.js +415 -386
  6. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  7. package/dist/data-structures/binary-tree/tree-multi-map.js +84 -76
  8. package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
  9. package/dist/data-structures/graph/abstract-graph.js +3 -0
  10. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
  11. package/dist/data-structures/linked-list/doubly-linked-list.js +16 -86
  12. package/dist/data-structures/linked-list/singly-linked-list.d.ts +27 -69
  13. package/dist/data-structures/linked-list/singly-linked-list.js +35 -79
  14. package/dist/data-structures/queue/deque.d.ts +0 -53
  15. package/dist/data-structures/queue/deque.js +0 -61
  16. package/dist/data-structures/queue/queue.d.ts +0 -70
  17. package/dist/data-structures/queue/queue.js +0 -87
  18. package/package.json +2 -2
  19. package/src/data-structures/base/iterable-base.ts +14 -10
  20. package/src/data-structures/binary-tree/binary-tree.ts +19 -19
  21. package/src/data-structures/binary-tree/rb-tree.ts +437 -395
  22. package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
  23. package/src/data-structures/graph/abstract-graph.ts +4 -0
  24. package/src/data-structures/heap/heap.ts +1 -1
  25. package/src/data-structures/linked-list/doubly-linked-list.ts +16 -94
  26. package/src/data-structures/linked-list/singly-linked-list.ts +35 -87
  27. package/src/data-structures/queue/deque.ts +0 -67
  28. package/src/data-structures/queue/queue.ts +0 -98
@@ -51,6 +51,7 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
51
51
  * @returns the sum of the count property of all nodes in the tree.
52
52
  */
53
53
  get count(): number;
54
+ getMutableCount(): number;
54
55
  /**
55
56
  * The function creates a new TreeMultiMapNode object with the specified key, value, and count.
56
57
  * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
@@ -58,10 +58,12 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
58
58
  * @returns the sum of the count property of all nodes in the tree.
59
59
  */
60
60
  get count() {
61
+ return this._count;
62
+ }
63
+ getMutableCount() {
61
64
  let sum = 0;
62
65
  this.dfs(node => (sum += node.count));
63
66
  return sum;
64
- // return this._count;
65
67
  }
66
68
  /**
67
69
  * The function creates a new TreeMultiMapNode object with the specified key, value, and count.
@@ -154,14 +156,15 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
154
156
  */
155
157
  add(keyOrNodeOrEntry, value, count = 1) {
156
158
  const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value, count);
157
- if (newNode === undefined)
159
+ const orgCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
160
+ const isSuccessAdded = super.add(newNode);
161
+ if (isSuccessAdded) {
162
+ this._count += orgCount;
163
+ return true;
164
+ }
165
+ else {
158
166
  return false;
159
- const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
160
- const inserted = super.add(newNode);
161
- if (inserted) {
162
- this._count += orgNodeCount;
163
167
  }
164
- return true;
165
168
  }
166
169
  /**
167
170
  * Time Complexity: O(log n)
@@ -188,86 +191,91 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
188
191
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
189
192
  */
190
193
  delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {
191
- const deleteResults = [];
192
194
  if (identifier === null)
193
- return deleteResults;
194
- // Helper function to perform deletion
195
- const deleteHelper = (node) => {
196
- // Initialize targetNode to the sentinel node
197
- let targetNode = this._Sentinel;
198
- let currentNode;
199
- // Find the node to be deleted based on the identifier
200
- while (node !== this._Sentinel) {
201
- // Update targetNode if the current node matches the identifier
202
- if (node && callback(node) === identifier) {
203
- targetNode = node;
204
- }
205
- // Move to the right or left based on the comparison with the identifier
206
- if (node && identifier && callback(node) <= identifier) {
207
- node = node.right;
208
- }
209
- else {
210
- node = node === null || node === void 0 ? void 0 : node.left;
211
- }
195
+ return [];
196
+ const results = [];
197
+ const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
198
+ if (!nodeToDelete) {
199
+ return results;
200
+ }
201
+ let originalColor = nodeToDelete.color;
202
+ let replacementNode;
203
+ if (!this.isRealNode(nodeToDelete.left)) {
204
+ replacementNode = nodeToDelete.right;
205
+ if (ignoreCount || nodeToDelete.count <= 1) {
206
+ this._transplant(nodeToDelete, nodeToDelete.right);
207
+ this._count -= nodeToDelete.count;
212
208
  }
213
- // If the target node is not found, decrement size and return
214
- if (targetNode === this._Sentinel) {
215
- return;
209
+ else {
210
+ nodeToDelete.count--;
211
+ this._count--;
212
+ results.push({ deleted: nodeToDelete, needBalanced: undefined });
213
+ return results;
216
214
  }
217
- if (ignoreCount || targetNode.count <= 1) {
218
- // Store the parent of the target node and its original color
219
- let parentNode = targetNode;
220
- let parentNodeOriginalColor = parentNode.color;
221
- // Handle deletion based on the number of children of the target node
222
- if (targetNode.left === this._Sentinel) {
223
- // Target node has no left child - deletion case 1
224
- currentNode = targetNode.right;
225
- this._rbTransplant(targetNode, targetNode.right);
226
- }
227
- else if (targetNode.right === this._Sentinel) {
228
- // Target node has no right child - deletion case 2
229
- currentNode = targetNode.left;
230
- this._rbTransplant(targetNode, targetNode.left);
215
+ }
216
+ else if (!this.isRealNode(nodeToDelete.right)) {
217
+ replacementNode = nodeToDelete.left;
218
+ if (ignoreCount || nodeToDelete.count <= 1) {
219
+ this._transplant(nodeToDelete, nodeToDelete.left);
220
+ this._count -= nodeToDelete.count;
221
+ }
222
+ else {
223
+ nodeToDelete.count--;
224
+ this._count--;
225
+ results.push({ deleted: nodeToDelete, needBalanced: undefined });
226
+ return results;
227
+ }
228
+ }
229
+ else {
230
+ const successor = this.getLeftMost(nodeToDelete.right);
231
+ if (successor) {
232
+ originalColor = successor.color;
233
+ replacementNode = successor.right;
234
+ if (successor.parent === nodeToDelete) {
235
+ if (this.isRealNode(replacementNode)) {
236
+ replacementNode.parent = successor;
237
+ }
231
238
  }
232
239
  else {
233
- // Target node has both left and right children - deletion case 3
234
- parentNode = this.getLeftMost(targetNode.right);
235
- parentNodeOriginalColor = parentNode.color;
236
- currentNode = parentNode.right;
237
- if (parentNode.parent === targetNode) {
238
- // Target node's right child becomes its parent's left child
239
- currentNode.parent = parentNode;
240
+ if (ignoreCount || nodeToDelete.count <= 1) {
241
+ this._transplant(successor, successor.right);
242
+ this._count -= nodeToDelete.count;
240
243
  }
241
244
  else {
242
- // Replace parentNode with its right child and update connections
243
- this._rbTransplant(parentNode, parentNode.right);
244
- parentNode.right = targetNode.right;
245
- parentNode.right.parent = parentNode;
245
+ nodeToDelete.count--;
246
+ this._count--;
247
+ results.push({ deleted: nodeToDelete, needBalanced: undefined });
248
+ return results;
249
+ }
250
+ successor.right = nodeToDelete.right;
251
+ if (this.isRealNode(successor.right)) {
252
+ successor.right.parent = successor;
246
253
  }
247
- // Replace the target node with its in-order successor
248
- this._rbTransplant(targetNode, parentNode);
249
- parentNode.left = targetNode.left;
250
- parentNode.left.parent = parentNode;
251
- parentNode.color = targetNode.color;
252
254
  }
253
- // Fix the Red-Black Tree properties after deletion
254
- if (parentNodeOriginalColor === types_1.RBTNColor.BLACK) {
255
- this._fixDelete(currentNode);
255
+ if (ignoreCount || nodeToDelete.count <= 1) {
256
+ this._transplant(nodeToDelete, successor);
257
+ this._count -= nodeToDelete.count;
256
258
  }
257
- // Decrement the size and store information about the deleted node
258
- this._size--;
259
- this._count -= targetNode.count;
260
- deleteResults.push({ deleted: targetNode, needBalanced: undefined });
261
- }
262
- else {
263
- targetNode.count--;
264
- this._count--;
259
+ else {
260
+ nodeToDelete.count--;
261
+ this._count--;
262
+ results.push({ deleted: nodeToDelete, needBalanced: undefined });
263
+ return results;
264
+ }
265
+ successor.left = nodeToDelete.left;
266
+ if (this.isRealNode(successor.left)) {
267
+ successor.left.parent = successor;
268
+ }
269
+ successor.color = nodeToDelete.color;
265
270
  }
266
- };
267
- // Call the helper function with the root of the tree
268
- deleteHelper(this.root);
269
- // Return the result array
270
- return deleteResults;
271
+ }
272
+ this._size--;
273
+ // If the original color was black, fix the tree
274
+ if (originalColor === types_1.RBTNColor.BLACK) {
275
+ this._deleteFixup(replacementNode);
276
+ }
277
+ results.push({ deleted: nodeToDelete, needBalanced: undefined });
278
+ return results;
271
279
  }
272
280
  /**
273
281
  * Time Complexity: O(1)
@@ -41,6 +41,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
41
41
  protected _vertexMap: Map<VertexKey, VO>;
42
42
  get vertexMap(): Map<VertexKey, VO>;
43
43
  set vertexMap(v: Map<VertexKey, VO>);
44
+ get size(): number;
44
45
  /**
45
46
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
46
47
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
@@ -50,6 +50,9 @@ class AbstractGraph extends base_1.IterableEntryBase {
50
50
  set vertexMap(v) {
51
51
  this._vertexMap = v;
52
52
  }
53
+ get size() {
54
+ return this._vertexMap.size;
55
+ }
53
56
  /**
54
57
  * Time Complexity: O(1) - Constant time for Map lookup.
55
58
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -131,24 +131,19 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
131
131
  * Space Complexity: O(1)
132
132
  */
133
133
  /**
134
- * Time Complexity: O(1)
135
- * Space Complexity: O(1)
136
- *
137
- * The push function adds a new node with the given value to the end of the doubly linked list.
138
- * @param {E} value - The value to be added to the linked list.
134
+ * The push function adds a new element to the end of a doubly linked list.
135
+ * @param {E} element - The "element" parameter represents the value that you want to add to the
136
+ * doubly linked list.
137
+ * @returns The `push` method is returning a boolean value, `true`.
139
138
  */
140
- push(value: E): boolean;
139
+ push(element: E): boolean;
141
140
  /**
142
141
  * Time Complexity: O(1)
143
142
  * Space Complexity: O(1)
144
143
  */
145
144
  /**
146
- * Time Complexity: O(1)
147
- * Space Complexity: O(1)
148
- *
149
- * The `pop()` function removes and returns the value of the last node in a doubly linked list.
150
- * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
151
- * list is empty, it returns undefined.
145
+ * The `pop()` function removes and returns the value of the last element in a linked list.
146
+ * @returns The method is returning the value of the removed node.
152
147
  */
153
148
  pop(): E | undefined;
154
149
  /**
@@ -156,12 +151,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
156
151
  * Space Complexity: O(1)
157
152
  */
158
153
  /**
159
- * Time Complexity: O(1)
160
- * Space Complexity: O(1)
161
- *
162
- * The `shift()` function removes and returns the value of the first node in a doubly linked list.
163
- * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
164
- * list.
154
+ * The `shift()` function removes and returns the value of the first element in a doubly linked list.
155
+ * @returns The value of the removed node.
165
156
  */
166
157
  shift(): E | undefined;
167
158
  /**
@@ -169,14 +160,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
169
160
  * Space Complexity: O(1)
170
161
  */
171
162
  /**
172
- * Time Complexity: O(1)
173
- * Space Complexity: O(1)
174
- *
175
- * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
176
- * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
177
- * doubly linked list.
163
+ * The unshift function adds a new element to the beginning of a doubly linked list.
164
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
165
+ * add to the beginning of the doubly linked list.
166
+ * @returns The `unshift` method is returning a boolean value, `true`.
178
167
  */
179
- unshift(value: E): boolean;
168
+ unshift(element: E): boolean;
180
169
  /**
181
170
  * Time Complexity: O(n)
182
171
  * Space Complexity: O(1)
@@ -449,57 +438,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
449
438
  * object.
450
439
  */
451
440
  map<T>(callback: ElementCallback<E, T>, thisArg?: any): DoublyLinkedList<T>;
452
- /**
453
- * Time Complexity: O(1)
454
- * Space Complexity: O(1)
455
- */
456
- /**
457
- * Time Complexity: O(1)
458
- * Space Complexity: O(1)
459
- *
460
- * The addLast function adds a new node with the given value to the end of the doubly linked list.
461
- * @param {E} value - The value to be added to the linked list.
462
- */
463
- addLast(value: E): boolean;
464
- /**
465
- * Time Complexity: O(1)
466
- * Space Complexity: O(1)
467
- */
468
- /**
469
- * Time Complexity: O(1)
470
- * Space Complexity: O(1)
471
- *
472
- * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
473
- * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
474
- * list is empty, it returns undefined.
475
- */
476
- pollLast(): E | undefined;
477
- /**
478
- * Time Complexity: O(1)
479
- * Space Complexity: O(1)
480
- */
481
- /**
482
- * Time Complexity: O(1)
483
- * Space Complexity: O(1)
484
- *
485
- * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
486
- * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
487
- * list.
488
- */
489
- pollFirst(): E | undefined;
490
- /**
491
- * Time Complexity: O(1)
492
- * Space Complexity: O(1)
493
- */
494
- /**
495
- * Time Complexity: O(1)
496
- * Space Complexity: O(1)
497
- *
498
- * The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
499
- * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
500
- * doubly linked list.
501
- */
502
- addFirst(value: E): void;
503
441
  /**
504
442
  * The function returns an iterator that iterates over the values of a linked list.
505
443
  */
@@ -161,14 +161,13 @@ class DoublyLinkedList extends base_1.IterableElementBase {
161
161
  * Space Complexity: O(1)
162
162
  */
163
163
  /**
164
- * Time Complexity: O(1)
165
- * Space Complexity: O(1)
166
- *
167
- * The push function adds a new node with the given value to the end of the doubly linked list.
168
- * @param {E} value - The value to be added to the linked list.
164
+ * The push function adds a new element to the end of a doubly linked list.
165
+ * @param {E} element - The "element" parameter represents the value that you want to add to the
166
+ * doubly linked list.
167
+ * @returns The `push` method is returning a boolean value, `true`.
169
168
  */
170
- push(value) {
171
- const newNode = new DoublyLinkedListNode(value);
169
+ push(element) {
170
+ const newNode = new DoublyLinkedListNode(element);
172
171
  if (!this.head) {
173
172
  this._head = newNode;
174
173
  this._tail = newNode;
@@ -186,12 +185,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
186
185
  * Space Complexity: O(1)
187
186
  */
188
187
  /**
189
- * Time Complexity: O(1)
190
- * Space Complexity: O(1)
191
- *
192
- * The `pop()` function removes and returns the value of the last node in a doubly linked list.
193
- * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
194
- * list is empty, it returns undefined.
188
+ * The `pop()` function removes and returns the value of the last element in a linked list.
189
+ * @returns The method is returning the value of the removed node.
195
190
  */
196
191
  pop() {
197
192
  if (!this.tail)
@@ -213,12 +208,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
213
208
  * Space Complexity: O(1)
214
209
  */
215
210
  /**
216
- * Time Complexity: O(1)
217
- * Space Complexity: O(1)
218
- *
219
- * The `shift()` function removes and returns the value of the first node in a doubly linked list.
220
- * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
221
- * list.
211
+ * The `shift()` function removes and returns the value of the first element in a doubly linked list.
212
+ * @returns The value of the removed node.
222
213
  */
223
214
  shift() {
224
215
  if (!this.head)
@@ -240,15 +231,13 @@ class DoublyLinkedList extends base_1.IterableElementBase {
240
231
  * Space Complexity: O(1)
241
232
  */
242
233
  /**
243
- * Time Complexity: O(1)
244
- * Space Complexity: O(1)
245
- *
246
- * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
247
- * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
248
- * doubly linked list.
234
+ * The unshift function adds a new element to the beginning of a doubly linked list.
235
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
236
+ * add to the beginning of the doubly linked list.
237
+ * @returns The `unshift` method is returning a boolean value, `true`.
249
238
  */
250
- unshift(value) {
251
- const newNode = new DoublyLinkedListNode(value);
239
+ unshift(element) {
240
+ const newNode = new DoublyLinkedListNode(element);
252
241
  if (!this.head) {
253
242
  this._head = newNode;
254
243
  this._tail = newNode;
@@ -738,65 +727,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
738
727
  }
739
728
  return mappedList;
740
729
  }
741
- /**
742
- * Time Complexity: O(1)
743
- * Space Complexity: O(1)
744
- */
745
- /**
746
- * Time Complexity: O(1)
747
- * Space Complexity: O(1)
748
- *
749
- * The addLast function adds a new node with the given value to the end of the doubly linked list.
750
- * @param {E} value - The value to be added to the linked list.
751
- */
752
- addLast(value) {
753
- return this.push(value);
754
- }
755
- /**
756
- * Time Complexity: O(1)
757
- * Space Complexity: O(1)
758
- */
759
- /**
760
- * Time Complexity: O(1)
761
- * Space Complexity: O(1)
762
- *
763
- * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
764
- * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
765
- * list is empty, it returns undefined.
766
- */
767
- pollLast() {
768
- return this.pop();
769
- }
770
- /**
771
- * Time Complexity: O(1)
772
- * Space Complexity: O(1)
773
- */
774
- /**
775
- * Time Complexity: O(1)
776
- * Space Complexity: O(1)
777
- *
778
- * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
779
- * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
780
- * list.
781
- */
782
- pollFirst() {
783
- return this.shift();
784
- }
785
- /**
786
- * Time Complexity: O(1)
787
- * Space Complexity: O(1)
788
- */
789
- /**
790
- * Time Complexity: O(1)
791
- * Space Complexity: O(1)
792
- *
793
- * The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
794
- * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
795
- * doubly linked list.
796
- */
797
- addFirst(value) {
798
- this.unshift(value);
799
- }
800
730
  /**
801
731
  * The function returns an iterator that iterates over the values of a linked list.
802
732
  */
@@ -60,6 +60,18 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
60
60
  * @returns The method is returning either a SinglyLinkedListNode object or undefined.
61
61
  */
62
62
  get tail(): SinglyLinkedListNode<E> | undefined;
63
+ /**
64
+ * The above function returns the value of the first element in a linked list, or undefined if the
65
+ * list is empty.
66
+ * @returns The value of the first node in the linked list, or undefined if the linked list is empty.
67
+ */
68
+ get first(): E | undefined;
69
+ /**
70
+ * The function returns the value of the last element in a linked list, or undefined if the list is
71
+ * empty.
72
+ * @returns The value of the last node in the linked list, or undefined if the linked list is empty.
73
+ */
74
+ get last(): E | undefined;
63
75
  protected _size: number;
64
76
  /**
65
77
  * The function returns the size of an object.
@@ -82,21 +94,6 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
82
94
  * @returns The `fromArray` function returns a `SinglyLinkedList` object.
83
95
  */
84
96
  static fromArray<E>(data: E[]): SinglyLinkedList<E>;
85
- /**
86
- * Time Complexity: O(1)
87
- * Space Complexity: O(1)
88
- * Constant time, as it involves basic pointer adjustments.
89
- * Constant space, as it only creates a new node.
90
- */
91
- /**
92
- * Time Complexity: O(1)
93
- * Space Complexity: O(1)
94
- *
95
- * The `push` function adds a new node with the given value to the end of a singly linked list.
96
- * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
97
- * any type (E) as specified in the generic type declaration of the class or function.
98
- */
99
- push(value: E): boolean;
100
97
  /**
101
98
  * Time Complexity: O(1)
102
99
  * Space Complexity: O(1)
@@ -105,11 +102,12 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
105
102
  * Time Complexity: O(1)
106
103
  * Space Complexity: O(1)
107
104
  *
108
- * The `push` function adds a new node with the given value to the end of a singly linked list.
109
- * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
110
- * any type (E) as specified in the generic type declaration of the class or function.
105
+ * The push function adds a new element to the end of a singly linked list.
106
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
107
+ * add to the linked list.
108
+ * @returns The `push` method is returning a boolean value, `true`.
111
109
  */
112
- addLast(value: E): boolean;
110
+ push(element: E): boolean;
113
111
  /**
114
112
  * Time Complexity: O(n)
115
113
  * Space Complexity: O(1)
@@ -119,26 +117,11 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
119
117
  * Time Complexity: O(n)
120
118
  * Space Complexity: O(1)
121
119
  *
122
- * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
123
- * pointers accordingly.
124
- * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
125
- * the linked list is empty, it returns `undefined`.
120
+ * The `pop` function removes and returns the value of the last element in a linked list.
121
+ * @returns The method is returning the value of the element that is being popped from the end of the
122
+ * list.
126
123
  */
127
124
  pop(): E | undefined;
128
- /**
129
- * Time Complexity: O(n)
130
- * Space Complexity: O(1)
131
- */
132
- /**
133
- * Time Complexity: O(n)
134
- * Space Complexity: O(1)
135
- *
136
- * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
137
- * pointers accordingly.
138
- * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
139
- * the linked list is empty, it returns `undefined`.
140
- */
141
- pollLast(): E | undefined;
142
125
  /**
143
126
  * Time Complexity: O(1)
144
127
  * Space Complexity: O(1)
@@ -147,8 +130,8 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
147
130
  * Time Complexity: O(1)
148
131
  * Space Complexity: O(1)
149
132
  *
150
- * The `shift()` function removes and returns the value of the first node in a linked list.
151
- * @returns The value of the node that is being removed from the beginning of the linked list.
133
+ * The `shift()` function removes and returns the value of the first element in a linked list.
134
+ * @returns The value of the removed node.
152
135
  */
153
136
  shift(): E | undefined;
154
137
  /**
@@ -159,40 +142,15 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
159
142
  * Time Complexity: O(1)
160
143
  * Space Complexity: O(1)
161
144
  *
162
- * The `pollFirst()` function removes and returns the value of the first node in a linked list.
163
- * @returns The value of the node that is being removed from the beginning of the linked list.
164
- */
165
- pollFirst(): E | undefined;
166
- /**
167
- * Time Complexity: O(1)
168
- * Space Complexity: O(1)
169
- */
170
- /**
171
- * Time Complexity: O(1)
172
- * Space Complexity: O(1)
173
- *
174
- * The unshift function adds a new node with the given value to the beginning of a singly linked list.
175
- * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
176
- * linked list.
177
- */
178
- unshift(value: E): boolean;
179
- /**
180
- * Time Complexity: O(1)
181
- * Space Complexity: O(1)
182
- */
183
- /**
184
- * Time Complexity: O(1)
185
- * Space Complexity: O(1)
186
- *
187
- * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
188
- * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
189
- * linked list.
145
+ * The unshift function adds a new element to the beginning of a singly linked list.
146
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
147
+ * add to the beginning of the singly linked list.
148
+ * @returns The `unshift` method is returning a boolean value, `true`.
190
149
  */
191
- addFirst(value: E): boolean;
150
+ unshift(element: E): boolean;
192
151
  /**
193
152
  * Time Complexity: O(n)
194
153
  * Space Complexity: O(1)
195
- * Linear time, where n is the index, as it may need to traverse the list to find the desired node.
196
154
  */
197
155
  /**
198
156
  * Time Complexity: O(n)