min-heap-typed 1.50.1 → 1.50.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +120 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +72 -47
  4. package/dist/data-structures/binary-tree/avl-tree.js +101 -72
  5. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  8. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  9. package/dist/data-structures/binary-tree/bst.d.ts +92 -79
  10. package/dist/data-structures/binary-tree/bst.js +68 -76
  11. package/dist/data-structures/binary-tree/rb-tree.d.ts +127 -57
  12. package/dist/data-structures/binary-tree/rb-tree.js +152 -99
  13. package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
  14. package/dist/data-structures/binary-tree/segment-tree.js +127 -10
  15. package/dist/data-structures/binary-tree/tree-multimap.d.ts +72 -58
  16. package/dist/data-structures/binary-tree/tree-multimap.js +102 -85
  17. package/dist/data-structures/graph/abstract-graph.d.ts +1 -78
  18. package/dist/data-structures/graph/abstract-graph.js +3 -189
  19. package/dist/data-structures/graph/directed-graph.d.ts +73 -0
  20. package/dist/data-structures/graph/directed-graph.js +131 -0
  21. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  22. package/dist/data-structures/graph/map-graph.js +14 -0
  23. package/dist/data-structures/graph/undirected-graph.d.ts +76 -7
  24. package/dist/data-structures/graph/undirected-graph.js +151 -18
  25. package/dist/data-structures/hash/hash-map.d.ts +254 -28
  26. package/dist/data-structures/hash/hash-map.js +347 -78
  27. package/dist/data-structures/heap/heap.d.ts +95 -25
  28. package/dist/data-structures/heap/heap.js +95 -26
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +141 -77
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +154 -106
  32. package/dist/data-structures/linked-list/singly-linked-list.js +164 -115
  33. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  34. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  35. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  36. package/dist/data-structures/matrix/matrix.js +50 -11
  37. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  38. package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
  39. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  40. package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
  41. package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
  42. package/dist/data-structures/priority-queue/priority-queue.js +8 -0
  43. package/dist/data-structures/queue/deque.d.ts +139 -35
  44. package/dist/data-structures/queue/deque.js +200 -62
  45. package/dist/data-structures/queue/queue.d.ts +103 -49
  46. package/dist/data-structures/queue/queue.js +111 -49
  47. package/dist/data-structures/stack/stack.d.ts +51 -21
  48. package/dist/data-structures/stack/stack.js +58 -22
  49. package/dist/data-structures/tree/tree.d.ts +57 -3
  50. package/dist/data-structures/tree/tree.js +77 -11
  51. package/dist/data-structures/trie/trie.d.ts +135 -34
  52. package/dist/data-structures/trie/trie.js +153 -33
  53. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  54. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  55. package/dist/types/utils/utils.d.ts +1 -0
  56. package/package.json +2 -2
  57. package/src/data-structures/base/iterable-base.ts +184 -19
  58. package/src/data-structures/binary-tree/avl-tree.ts +134 -100
  59. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  60. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  61. package/src/data-structures/binary-tree/bst.ts +127 -136
  62. package/src/data-structures/binary-tree/rb-tree.ts +199 -166
  63. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  64. package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
  65. package/src/data-structures/graph/abstract-graph.ts +4 -211
  66. package/src/data-structures/graph/directed-graph.ts +152 -0
  67. package/src/data-structures/graph/map-graph.ts +15 -0
  68. package/src/data-structures/graph/undirected-graph.ts +171 -19
  69. package/src/data-structures/hash/hash-map.ts +389 -96
  70. package/src/data-structures/heap/heap.ts +97 -26
  71. package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
  72. package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
  73. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  74. package/src/data-structures/matrix/matrix.ts +52 -12
  75. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  76. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  77. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  78. package/src/data-structures/queue/deque.ts +225 -70
  79. package/src/data-structures/queue/queue.ts +118 -49
  80. package/src/data-structures/stack/stack.ts +63 -23
  81. package/src/data-structures/tree/tree.ts +89 -15
  82. package/src/data-structures/trie/trie.ts +173 -38
  83. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  84. package/src/types/data-structures/hash/hash-map.ts +4 -3
  85. package/src/types/utils/utils.ts +2 -0
@@ -24,8 +24,16 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
24
24
  */
25
25
  constructor(elements?: Iterable<E>);
26
26
  protected _elements: E[];
27
+ /**
28
+ * The elements function returns the elements of this set.
29
+ * @return An array of the elements in the stack
30
+ */
27
31
  get elements(): E[];
28
32
  protected _offset: number;
33
+ /**
34
+ * The offset function returns the offset of the current page.
35
+ * @return The value of the protected variable _offset
36
+ */
29
37
  get offset(): number;
30
38
  /**
31
39
  * The size function returns the number of elements in an array.
@@ -33,8 +41,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
33
41
  */
34
42
  get size(): number;
35
43
  /**
36
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
37
- * Space Complexity: O(1) - no additional space is used.
44
+ * Time Complexity: O(1)
45
+ * Space Complexity: O(1)
46
+ */
47
+ /**
48
+ * Time Complexity: O(1)
49
+ * Space Complexity: O(1)
38
50
  *
39
51
  * The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
40
52
  * @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
@@ -42,12 +54,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
42
54
  */
43
55
  get first(): E | undefined;
44
56
  /**
45
- * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
46
- * Space Complexity: O(1) - no additional space is used.
57
+ * Time Complexity: O(1)
58
+ * Space Complexity: O(1)
47
59
  */
48
60
  /**
49
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
50
- * Space Complexity: O(1) - no additional space is used.
61
+ * Time Complexity: O(1)
62
+ * Space Complexity: O(1)
51
63
  *
52
64
  * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
53
65
  * @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
@@ -55,10 +67,13 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
55
67
  */
56
68
  get last(): E | undefined;
57
69
  /**
58
- * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
59
- * Space Complexity: O(1) - no additional space is used.
70
+ * Time Complexity: O(n)
71
+ * Space Complexity: O(n)
60
72
  */
61
73
  /**
74
+ * Time Complexity: O(n)
75
+ * Space Complexity: O(n)
76
+ *
62
77
  * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
63
78
  * @public
64
79
  * @static
@@ -68,12 +83,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
68
83
  */
69
84
  static fromArray<E>(elements: E[]): Queue<E>;
70
85
  /**
71
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
72
- * Space Complexity: O(1) - no additional space is used.
86
+ * Time Complexity: O(1)
87
+ * Space Complexity: O(1)
73
88
  */
74
89
  /**
75
- * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
76
- * Space Complexity: O(1) - no additional space is used.
90
+ * Time Complexity: O(1)
91
+ * Space Complexity: O(1)
77
92
  *
78
93
  * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
79
94
  * @param {E} element - The `element` parameter represents the element that you want to add to the queue.
@@ -81,12 +96,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
81
96
  */
82
97
  push(element: E): boolean;
83
98
  /**
84
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
85
- * Space Complexity: O(1) - no additional space is used.
99
+ * Time Complexity: O(1)
100
+ * Space Complexity: O(1)
86
101
  */
87
102
  /**
88
- * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
89
- * Space Complexity: O(1) - no additional space is used.
103
+ * Time Complexity: O(1)
104
+ * Space Complexity: O(1)
90
105
  *
91
106
  * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
92
107
  * necessary to optimize performance.
@@ -94,12 +109,24 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
94
109
  */
95
110
  shift(): E | undefined;
96
111
  /**
97
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
98
- * Space Complexity: O(1) - no additional space is used.
112
+ * The delete function removes an element from the list.
113
+ * @param element: E Specify the element to be deleted
114
+ * @return A boolean value indicating whether the element was successfully deleted or not
115
+ */
116
+ delete(element: E): boolean;
117
+ /**
118
+ * The deleteAt function deletes the element at a given index.
119
+ * @param index: number Determine the index of the element to be deleted
120
+ * @return A boolean value
121
+ */
122
+ deleteAt(index: number): boolean;
123
+ /**
124
+ * Time Complexity: O(1)
125
+ * Space Complexity: O(1)
99
126
  */
100
127
  /**
101
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
102
- * Space Complexity: O(1) - no additional space is used.
128
+ * Time Complexity: O(1)
129
+ * Space Complexity: O(1)
103
130
  *
104
131
  * The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
105
132
  * @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
@@ -107,12 +134,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
107
134
  */
108
135
  peek(): E | undefined;
109
136
  /**
110
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
111
- * Space Complexity: O(1) - no additional space is used.
137
+ * Time Complexity: O(1)
138
+ * Space Complexity: O(1)
112
139
  */
113
140
  /**
114
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
115
- * Space Complexity: O(1) - no additional space is used.
141
+ * Time Complexity: O(1)
142
+ * Space Complexity: O(1)
116
143
  *
117
144
  * The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
118
145
  * @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
@@ -120,75 +147,83 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
120
147
  */
121
148
  peekLast(): E | undefined;
122
149
  /**
123
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
124
- * Space Complexity: O(1) - no additional space is used.
150
+ * Time Complexity: O(1)
151
+ * Space Complexity: O(1)
125
152
  */
126
153
  /**
127
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
128
- * Space Complexity: O(1) - no additional space is used.
154
+ * Time Complexity: O(1)
155
+ * Space Complexity: O(1)
129
156
  *
130
157
  * The enqueue function adds a value to the end of a queue.
131
158
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
132
159
  */
133
160
  enqueue(value: E): boolean;
134
161
  /**
135
- * Time Complexity: O(n) - same as shift().
136
- * Space Complexity: O(1) - same as shift().
162
+ * Time Complexity: O(1)
163
+ * Space Complexity: O(1)
137
164
  */
138
165
  /**
139
- * Time Complexity: O(n) - same as shift().
140
- * Space Complexity: O(1) - same as shift().
166
+ * Time Complexity: O(1)
167
+ * Space Complexity: O(1)
141
168
  *
142
169
  * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
143
170
  * @returns The method is returning a value of type E or undefined.
144
171
  */
145
172
  dequeue(): E | undefined;
146
173
  /**
147
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
148
- * Space Complexity: O(1) - no additional space is used.
174
+ * Time Complexity: O(1)
175
+ * Space Complexity: O(1)
149
176
  */
150
177
  /**
151
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
152
- * Space Complexity: O(1) - no additional space is used.
178
+ * Time Complexity: O(1)
179
+ * Space Complexity: O(1)
153
180
  *
154
181
  * @param index
155
182
  */
156
- getAt(index: number): E | undefined;
183
+ at(index: number): E | undefined;
157
184
  /**
158
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
159
- * Space Complexity: O(1) - no additional space is used.
185
+ * Time Complexity: O(1)
186
+ * Space Complexity: O(1)
160
187
  */
161
188
  /**
162
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
163
- * Space Complexity: O(1) - no additional space is used.
189
+ * Time Complexity: O(1)
190
+ * Space Complexity: O(1)
164
191
  *
165
192
  * The function checks if a data structure is empty by comparing its size to zero.
166
193
  * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
167
194
  */
168
195
  isEmpty(): boolean;
169
196
  /**
170
- * Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
171
- * Space Complexity: O(n) - where n is the number of elements in the queue.
197
+ * Time Complexity: O(1)
198
+ * Space Complexity: O(n)
172
199
  */
173
200
  /**
174
- * Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
175
- * Space Complexity: O(n) - where n is the number of elements in the queue.
201
+ * Time Complexity: O(1)
202
+ * Space Complexity: O(n)
176
203
  *
177
204
  * The toArray() function returns an array of elements from the current offset to the end of the _elements array.
178
205
  * @returns An array of type E is being returned.
179
206
  */
180
207
  toArray(): E[];
181
208
  /**
209
+ * Time Complexity: O(1)
210
+ * Space Complexity: O(1)
211
+ */
212
+ /**
213
+ * Time Complexity: O(1)
214
+ * Space Complexity: O(1)
215
+ *
182
216
  * The clear function resets the elements array and offset to their initial values.
183
217
  */
184
218
  clear(): void;
185
219
  /**
186
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
187
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
220
+ * Time Complexity: O(n)
221
+ * Space Complexity: O(n)
222
+ * where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
188
223
  */
189
224
  /**
190
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
191
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
225
+ * Time Complexity: O(n)
226
+ * Space Complexity: O(n)
192
227
  *
193
228
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
194
229
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
@@ -238,6 +273,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
238
273
  * Time Complexity: O(n)
239
274
  * Space Complexity: O(n)
240
275
  */
276
+ /**
277
+ * Time Complexity: O(n)
278
+ * Space Complexity: O(n)
279
+ *
280
+ * The function `_getIterator` returns an iterable iterator for the elements in the class.
281
+ */
241
282
  protected _getIterator(): IterableIterator<E>;
242
283
  }
243
284
  /**
@@ -267,4 +308,17 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
267
308
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
268
309
  */
269
310
  peek(): E | undefined;
311
+ /**
312
+ * Time Complexity: O(n)
313
+ * Space Complexity: O(n)
314
+ */
315
+ /**
316
+ * Time Complexity: O(n)
317
+ * Space Complexity: O(n)
318
+ * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
319
+ * the current instance.
320
+ * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
321
+ * values as the original `LinkedListQueue`.
322
+ */
323
+ clone(): LinkedListQueue<E>;
270
324
  }
@@ -28,9 +28,17 @@ class Queue extends base_1.IterableElementBase {
28
28
  this.push(el);
29
29
  }
30
30
  }
31
+ /**
32
+ * The elements function returns the elements of this set.
33
+ * @return An array of the elements in the stack
34
+ */
31
35
  get elements() {
32
36
  return this._elements;
33
37
  }
38
+ /**
39
+ * The offset function returns the offset of the current page.
40
+ * @return The value of the protected variable _offset
41
+ */
34
42
  get offset() {
35
43
  return this._offset;
36
44
  }
@@ -42,8 +50,12 @@ class Queue extends base_1.IterableElementBase {
42
50
  return this.elements.length - this.offset;
43
51
  }
44
52
  /**
45
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
46
- * Space Complexity: O(1) - no additional space is used.
53
+ * Time Complexity: O(1)
54
+ * Space Complexity: O(1)
55
+ */
56
+ /**
57
+ * Time Complexity: O(1)
58
+ * Space Complexity: O(1)
47
59
  *
48
60
  * The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
49
61
  * @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
@@ -53,12 +65,12 @@ class Queue extends base_1.IterableElementBase {
53
65
  return this.size > 0 ? this.elements[this.offset] : undefined;
54
66
  }
55
67
  /**
56
- * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
57
- * Space Complexity: O(1) - no additional space is used.
68
+ * Time Complexity: O(1)
69
+ * Space Complexity: O(1)
58
70
  */
59
71
  /**
60
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
61
- * Space Complexity: O(1) - no additional space is used.
72
+ * Time Complexity: O(1)
73
+ * Space Complexity: O(1)
62
74
  *
63
75
  * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
64
76
  * @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
@@ -68,10 +80,13 @@ class Queue extends base_1.IterableElementBase {
68
80
  return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
69
81
  }
70
82
  /**
71
- * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
72
- * Space Complexity: O(1) - no additional space is used.
83
+ * Time Complexity: O(n)
84
+ * Space Complexity: O(n)
73
85
  */
74
86
  /**
87
+ * Time Complexity: O(n)
88
+ * Space Complexity: O(n)
89
+ *
75
90
  * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
76
91
  * @public
77
92
  * @static
@@ -83,12 +98,12 @@ class Queue extends base_1.IterableElementBase {
83
98
  return new Queue(elements);
84
99
  }
85
100
  /**
86
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
87
- * Space Complexity: O(1) - no additional space is used.
101
+ * Time Complexity: O(1)
102
+ * Space Complexity: O(1)
88
103
  */
89
104
  /**
90
- * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
91
- * Space Complexity: O(1) - no additional space is used.
105
+ * Time Complexity: O(1)
106
+ * Space Complexity: O(1)
92
107
  *
93
108
  * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
94
109
  * @param {E} element - The `element` parameter represents the element that you want to add to the queue.
@@ -99,12 +114,12 @@ class Queue extends base_1.IterableElementBase {
99
114
  return true;
100
115
  }
101
116
  /**
102
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
103
- * Space Complexity: O(1) - no additional space is used.
117
+ * Time Complexity: O(1)
118
+ * Space Complexity: O(1)
104
119
  */
105
120
  /**
106
- * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
107
- * Space Complexity: O(1) - no additional space is used.
121
+ * Time Complexity: O(1)
122
+ * Space Complexity: O(1)
108
123
  *
109
124
  * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
110
125
  * necessary to optimize performance.
@@ -124,12 +139,30 @@ class Queue extends base_1.IterableElementBase {
124
139
  return first;
125
140
  }
126
141
  /**
127
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
128
- * Space Complexity: O(1) - no additional space is used.
142
+ * The delete function removes an element from the list.
143
+ * @param element: E Specify the element to be deleted
144
+ * @return A boolean value indicating whether the element was successfully deleted or not
145
+ */
146
+ delete(element) {
147
+ const index = this.elements.indexOf(element);
148
+ return this.deleteAt(index);
149
+ }
150
+ /**
151
+ * The deleteAt function deletes the element at a given index.
152
+ * @param index: number Determine the index of the element to be deleted
153
+ * @return A boolean value
154
+ */
155
+ deleteAt(index) {
156
+ const spliced = this.elements.splice(index, 1);
157
+ return spliced.length === 1;
158
+ }
159
+ /**
160
+ * Time Complexity: O(1)
161
+ * Space Complexity: O(1)
129
162
  */
130
163
  /**
131
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
132
- * Space Complexity: O(1) - no additional space is used.
164
+ * Time Complexity: O(1)
165
+ * Space Complexity: O(1)
133
166
  *
134
167
  * The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
135
168
  * @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
@@ -139,12 +172,12 @@ class Queue extends base_1.IterableElementBase {
139
172
  return this.first;
140
173
  }
141
174
  /**
142
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
143
- * Space Complexity: O(1) - no additional space is used.
175
+ * Time Complexity: O(1)
176
+ * Space Complexity: O(1)
144
177
  */
145
178
  /**
146
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
147
- * Space Complexity: O(1) - no additional space is used.
179
+ * Time Complexity: O(1)
180
+ * Space Complexity: O(1)
148
181
  *
149
182
  * The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
150
183
  * @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
@@ -154,12 +187,12 @@ class Queue extends base_1.IterableElementBase {
154
187
  return this.last;
155
188
  }
156
189
  /**
157
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
158
- * Space Complexity: O(1) - no additional space is used.
190
+ * Time Complexity: O(1)
191
+ * Space Complexity: O(1)
159
192
  */
160
193
  /**
161
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
162
- * Space Complexity: O(1) - no additional space is used.
194
+ * Time Complexity: O(1)
195
+ * Space Complexity: O(1)
163
196
  *
164
197
  * The enqueue function adds a value to the end of a queue.
165
198
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -168,12 +201,12 @@ class Queue extends base_1.IterableElementBase {
168
201
  return this.push(value);
169
202
  }
170
203
  /**
171
- * Time Complexity: O(n) - same as shift().
172
- * Space Complexity: O(1) - same as shift().
204
+ * Time Complexity: O(1)
205
+ * Space Complexity: O(1)
173
206
  */
174
207
  /**
175
- * Time Complexity: O(n) - same as shift().
176
- * Space Complexity: O(1) - same as shift().
208
+ * Time Complexity: O(1)
209
+ * Space Complexity: O(1)
177
210
  *
178
211
  * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
179
212
  * @returns The method is returning a value of type E or undefined.
@@ -182,25 +215,25 @@ class Queue extends base_1.IterableElementBase {
182
215
  return this.shift();
183
216
  }
184
217
  /**
185
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
186
- * Space Complexity: O(1) - no additional space is used.
218
+ * Time Complexity: O(1)
219
+ * Space Complexity: O(1)
187
220
  */
188
221
  /**
189
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
190
- * Space Complexity: O(1) - no additional space is used.
222
+ * Time Complexity: O(1)
223
+ * Space Complexity: O(1)
191
224
  *
192
225
  * @param index
193
226
  */
194
- getAt(index) {
227
+ at(index) {
195
228
  return this.elements[index];
196
229
  }
197
230
  /**
198
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
199
- * Space Complexity: O(1) - no additional space is used.
231
+ * Time Complexity: O(1)
232
+ * Space Complexity: O(1)
200
233
  */
201
234
  /**
202
- * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
203
- * Space Complexity: O(1) - no additional space is used.
235
+ * Time Complexity: O(1)
236
+ * Space Complexity: O(1)
204
237
  *
205
238
  * The function checks if a data structure is empty by comparing its size to zero.
206
239
  * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
@@ -209,12 +242,12 @@ class Queue extends base_1.IterableElementBase {
209
242
  return this.size === 0;
210
243
  }
211
244
  /**
212
- * Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
213
- * Space Complexity: O(n) - where n is the number of elements in the queue.
245
+ * Time Complexity: O(1)
246
+ * Space Complexity: O(n)
214
247
  */
215
248
  /**
216
- * Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
217
- * Space Complexity: O(n) - where n is the number of elements in the queue.
249
+ * Time Complexity: O(1)
250
+ * Space Complexity: O(n)
218
251
  *
219
252
  * The toArray() function returns an array of elements from the current offset to the end of the _elements array.
220
253
  * @returns An array of type E is being returned.
@@ -223,6 +256,13 @@ class Queue extends base_1.IterableElementBase {
223
256
  return this.elements.slice(this.offset);
224
257
  }
225
258
  /**
259
+ * Time Complexity: O(1)
260
+ * Space Complexity: O(1)
261
+ */
262
+ /**
263
+ * Time Complexity: O(1)
264
+ * Space Complexity: O(1)
265
+ *
226
266
  * The clear function resets the elements array and offset to their initial values.
227
267
  */
228
268
  clear() {
@@ -230,12 +270,13 @@ class Queue extends base_1.IterableElementBase {
230
270
  this._offset = 0;
231
271
  }
232
272
  /**
233
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
234
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
273
+ * Time Complexity: O(n)
274
+ * Space Complexity: O(n)
275
+ * where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
235
276
  */
236
277
  /**
237
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
238
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
278
+ * Time Complexity: O(n)
279
+ * Space Complexity: O(n)
239
280
  *
240
281
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
241
282
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
@@ -305,6 +346,12 @@ class Queue extends base_1.IterableElementBase {
305
346
  * Time Complexity: O(n)
306
347
  * Space Complexity: O(n)
307
348
  */
349
+ /**
350
+ * Time Complexity: O(n)
351
+ * Space Complexity: O(n)
352
+ *
353
+ * The function `_getIterator` returns an iterable iterator for the elements in the class.
354
+ */
308
355
  *_getIterator() {
309
356
  for (const item of this.elements) {
310
357
  yield item;
@@ -348,5 +395,20 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
348
395
  peek() {
349
396
  return this.first;
350
397
  }
398
+ /**
399
+ * Time Complexity: O(n)
400
+ * Space Complexity: O(n)
401
+ */
402
+ /**
403
+ * Time Complexity: O(n)
404
+ * Space Complexity: O(n)
405
+ * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
406
+ * the current instance.
407
+ * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
408
+ * values as the original `LinkedListQueue`.
409
+ */
410
+ clone() {
411
+ return new LinkedListQueue(this.values());
412
+ }
351
413
  }
352
414
  exports.LinkedListQueue = LinkedListQueue;