min-heap-typed 1.50.2 → 1.50.4
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.
- package/dist/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +49 -11
- package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/data-structures/binary-tree/bst.js +51 -20
- package/dist/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/data-structures/binary-tree/index.js +2 -1
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/data-structures/binary-tree/tree-multi-map.js +399 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/data-structures/graph/abstract-graph.js +0 -189
- package/dist/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/data-structures/graph/directed-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/data-structures/graph/undirected-graph.js +126 -18
- package/dist/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/data-structures/hash/hash-map.js +196 -62
- package/dist/data-structures/heap/heap.d.ts +29 -19
- package/dist/data-structures/heap/heap.js +29 -20
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix.js +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +95 -21
- package/dist/data-structures/queue/deque.js +100 -16
- package/dist/data-structures/queue/queue.d.ts +65 -45
- package/dist/data-structures/queue/queue.js +65 -45
- package/dist/data-structures/stack/stack.d.ts +36 -22
- package/dist/data-structures/stack/stack.js +36 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +100 -36
- package/dist/data-structures/trie/trie.js +115 -36
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/index.js +2 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +2 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -32,7 +32,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
32
32
|
protected _offset: number;
|
|
33
33
|
/**
|
|
34
34
|
* The offset function returns the offset of the current page.
|
|
35
|
-
* @return The value of the
|
|
35
|
+
* @return The value of the protected variable _offset
|
|
36
36
|
*/
|
|
37
37
|
get offset(): number;
|
|
38
38
|
/**
|
|
@@ -41,8 +41,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
41
41
|
*/
|
|
42
42
|
get size(): number;
|
|
43
43
|
/**
|
|
44
|
-
* Time Complexity: O(1)
|
|
45
|
-
* Space Complexity: O(1)
|
|
44
|
+
* Time Complexity: O(1)
|
|
45
|
+
* Space Complexity: O(1)
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Time Complexity: O(1)
|
|
49
|
+
* Space Complexity: O(1)
|
|
46
50
|
*
|
|
47
51
|
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
48
52
|
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -50,12 +54,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
50
54
|
*/
|
|
51
55
|
get first(): E | undefined;
|
|
52
56
|
/**
|
|
53
|
-
* Time Complexity: O(1)
|
|
54
|
-
* Space Complexity: O(1)
|
|
57
|
+
* Time Complexity: O(1)
|
|
58
|
+
* Space Complexity: O(1)
|
|
55
59
|
*/
|
|
56
60
|
/**
|
|
57
|
-
* Time Complexity: O(1)
|
|
58
|
-
* Space Complexity: O(1)
|
|
61
|
+
* Time Complexity: O(1)
|
|
62
|
+
* Space Complexity: O(1)
|
|
59
63
|
*
|
|
60
64
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
61
65
|
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -63,10 +67,13 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
63
67
|
*/
|
|
64
68
|
get last(): E | undefined;
|
|
65
69
|
/**
|
|
66
|
-
* Time Complexity: O(n)
|
|
67
|
-
* Space Complexity: O(
|
|
70
|
+
* Time Complexity: O(n)
|
|
71
|
+
* Space Complexity: O(n)
|
|
68
72
|
*/
|
|
69
73
|
/**
|
|
74
|
+
* Time Complexity: O(n)
|
|
75
|
+
* Space Complexity: O(n)
|
|
76
|
+
*
|
|
70
77
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
71
78
|
* @public
|
|
72
79
|
* @static
|
|
@@ -76,12 +83,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
76
83
|
*/
|
|
77
84
|
static fromArray<E>(elements: E[]): Queue<E>;
|
|
78
85
|
/**
|
|
79
|
-
* Time Complexity: O(1)
|
|
80
|
-
* Space Complexity: O(1)
|
|
86
|
+
* Time Complexity: O(1)
|
|
87
|
+
* Space Complexity: O(1)
|
|
81
88
|
*/
|
|
82
89
|
/**
|
|
83
|
-
* Time Complexity: O(1)
|
|
84
|
-
* Space Complexity: O(1)
|
|
90
|
+
* Time Complexity: O(1)
|
|
91
|
+
* Space Complexity: O(1)
|
|
85
92
|
*
|
|
86
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.
|
|
87
94
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
@@ -89,12 +96,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
89
96
|
*/
|
|
90
97
|
push(element: E): boolean;
|
|
91
98
|
/**
|
|
92
|
-
* Time Complexity: O(1)
|
|
93
|
-
* Space Complexity: O(1)
|
|
99
|
+
* Time Complexity: O(1)
|
|
100
|
+
* Space Complexity: O(1)
|
|
94
101
|
*/
|
|
95
102
|
/**
|
|
96
|
-
* Time Complexity: O(
|
|
97
|
-
* Space Complexity: O(1)
|
|
103
|
+
* Time Complexity: O(1)
|
|
104
|
+
* Space Complexity: O(1)
|
|
98
105
|
*
|
|
99
106
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
100
107
|
* necessary to optimize performance.
|
|
@@ -114,12 +121,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
114
121
|
*/
|
|
115
122
|
deleteAt(index: number): boolean;
|
|
116
123
|
/**
|
|
117
|
-
* Time Complexity: O(1)
|
|
118
|
-
* Space Complexity: O(1)
|
|
124
|
+
* Time Complexity: O(1)
|
|
125
|
+
* Space Complexity: O(1)
|
|
119
126
|
*/
|
|
120
127
|
/**
|
|
121
|
-
* Time Complexity: O(1)
|
|
122
|
-
* Space Complexity: O(1)
|
|
128
|
+
* Time Complexity: O(1)
|
|
129
|
+
* Space Complexity: O(1)
|
|
123
130
|
*
|
|
124
131
|
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
125
132
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -127,12 +134,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
127
134
|
*/
|
|
128
135
|
peek(): E | undefined;
|
|
129
136
|
/**
|
|
130
|
-
* Time Complexity: O(1)
|
|
131
|
-
* Space Complexity: O(1)
|
|
137
|
+
* Time Complexity: O(1)
|
|
138
|
+
* Space Complexity: O(1)
|
|
132
139
|
*/
|
|
133
140
|
/**
|
|
134
|
-
* Time Complexity: O(1)
|
|
135
|
-
* Space Complexity: O(1)
|
|
141
|
+
* Time Complexity: O(1)
|
|
142
|
+
* Space Complexity: O(1)
|
|
136
143
|
*
|
|
137
144
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
138
145
|
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -140,65 +147,72 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
140
147
|
*/
|
|
141
148
|
peekLast(): E | undefined;
|
|
142
149
|
/**
|
|
143
|
-
* Time Complexity: O(1)
|
|
144
|
-
* Space Complexity: O(1)
|
|
150
|
+
* Time Complexity: O(1)
|
|
151
|
+
* Space Complexity: O(1)
|
|
145
152
|
*/
|
|
146
153
|
/**
|
|
147
|
-
* Time Complexity: O(1)
|
|
148
|
-
* Space Complexity: O(1)
|
|
154
|
+
* Time Complexity: O(1)
|
|
155
|
+
* Space Complexity: O(1)
|
|
149
156
|
*
|
|
150
157
|
* The enqueue function adds a value to the end of a queue.
|
|
151
158
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
152
159
|
*/
|
|
153
160
|
enqueue(value: E): boolean;
|
|
154
161
|
/**
|
|
155
|
-
* Time Complexity: O(
|
|
156
|
-
* Space Complexity: O(1)
|
|
162
|
+
* Time Complexity: O(1)
|
|
163
|
+
* Space Complexity: O(1)
|
|
157
164
|
*/
|
|
158
165
|
/**
|
|
159
|
-
* Time Complexity: O(
|
|
160
|
-
* Space Complexity: O(1)
|
|
166
|
+
* Time Complexity: O(1)
|
|
167
|
+
* Space Complexity: O(1)
|
|
161
168
|
*
|
|
162
169
|
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
163
170
|
* @returns The method is returning a value of type E or undefined.
|
|
164
171
|
*/
|
|
165
172
|
dequeue(): E | undefined;
|
|
166
173
|
/**
|
|
167
|
-
* Time Complexity: O(1)
|
|
168
|
-
* Space Complexity: O(1)
|
|
174
|
+
* Time Complexity: O(1)
|
|
175
|
+
* Space Complexity: O(1)
|
|
169
176
|
*/
|
|
170
177
|
/**
|
|
171
|
-
* Time Complexity: O(1)
|
|
172
|
-
* Space Complexity: O(1)
|
|
178
|
+
* Time Complexity: O(1)
|
|
179
|
+
* Space Complexity: O(1)
|
|
173
180
|
*
|
|
174
181
|
* @param index
|
|
175
182
|
*/
|
|
176
183
|
at(index: number): E | undefined;
|
|
177
184
|
/**
|
|
178
|
-
* Time Complexity: O(1)
|
|
179
|
-
* Space Complexity: O(1)
|
|
185
|
+
* Time Complexity: O(1)
|
|
186
|
+
* Space Complexity: O(1)
|
|
180
187
|
*/
|
|
181
188
|
/**
|
|
182
|
-
* Time Complexity: O(1)
|
|
183
|
-
* Space Complexity: O(1)
|
|
189
|
+
* Time Complexity: O(1)
|
|
190
|
+
* Space Complexity: O(1)
|
|
184
191
|
*
|
|
185
192
|
* The function checks if a data structure is empty by comparing its size to zero.
|
|
186
193
|
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
187
194
|
*/
|
|
188
195
|
isEmpty(): boolean;
|
|
189
196
|
/**
|
|
190
|
-
* Time Complexity: O(1)
|
|
191
|
-
* Space Complexity: O(n)
|
|
197
|
+
* Time Complexity: O(1)
|
|
198
|
+
* Space Complexity: O(n)
|
|
192
199
|
*/
|
|
193
200
|
/**
|
|
194
|
-
* Time Complexity: O(1)
|
|
195
|
-
* Space Complexity: O(n)
|
|
201
|
+
* Time Complexity: O(1)
|
|
202
|
+
* Space Complexity: O(n)
|
|
196
203
|
*
|
|
197
204
|
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
198
205
|
* @returns An array of type E is being returned.
|
|
199
206
|
*/
|
|
200
207
|
toArray(): E[];
|
|
201
208
|
/**
|
|
209
|
+
* Time Complexity: O(1)
|
|
210
|
+
* Space Complexity: O(1)
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* Time Complexity: O(1)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*
|
|
202
216
|
* The clear function resets the elements array and offset to their initial values.
|
|
203
217
|
*/
|
|
204
218
|
clear(): void;
|
|
@@ -259,6 +273,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
259
273
|
* Time Complexity: O(n)
|
|
260
274
|
* Space Complexity: O(n)
|
|
261
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
|
+
*/
|
|
262
282
|
protected _getIterator(): IterableIterator<E>;
|
|
263
283
|
}
|
|
264
284
|
/**
|
|
@@ -37,7 +37,7 @@ class Queue extends base_1.IterableElementBase {
|
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* The offset function returns the offset of the current page.
|
|
40
|
-
* @return The value of the
|
|
40
|
+
* @return The value of the protected variable _offset
|
|
41
41
|
*/
|
|
42
42
|
get offset() {
|
|
43
43
|
return this._offset;
|
|
@@ -50,8 +50,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
50
50
|
return this.elements.length - this.offset;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Time Complexity: O(1)
|
|
54
|
-
* Space Complexity: O(1)
|
|
53
|
+
* Time Complexity: O(1)
|
|
54
|
+
* Space Complexity: O(1)
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Time Complexity: O(1)
|
|
58
|
+
* Space Complexity: O(1)
|
|
55
59
|
*
|
|
56
60
|
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
57
61
|
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -61,12 +65,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
61
65
|
return this.size > 0 ? this.elements[this.offset] : undefined;
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
|
-
* Time Complexity: O(1)
|
|
65
|
-
* Space Complexity: O(1)
|
|
68
|
+
* Time Complexity: O(1)
|
|
69
|
+
* Space Complexity: O(1)
|
|
66
70
|
*/
|
|
67
71
|
/**
|
|
68
|
-
* Time Complexity: O(1)
|
|
69
|
-
* Space Complexity: O(1)
|
|
72
|
+
* Time Complexity: O(1)
|
|
73
|
+
* Space Complexity: O(1)
|
|
70
74
|
*
|
|
71
75
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
72
76
|
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -76,10 +80,13 @@ class Queue extends base_1.IterableElementBase {
|
|
|
76
80
|
return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
|
|
77
81
|
}
|
|
78
82
|
/**
|
|
79
|
-
* Time Complexity: O(n)
|
|
80
|
-
* Space Complexity: O(
|
|
83
|
+
* Time Complexity: O(n)
|
|
84
|
+
* Space Complexity: O(n)
|
|
81
85
|
*/
|
|
82
86
|
/**
|
|
87
|
+
* Time Complexity: O(n)
|
|
88
|
+
* Space Complexity: O(n)
|
|
89
|
+
*
|
|
83
90
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
84
91
|
* @public
|
|
85
92
|
* @static
|
|
@@ -91,12 +98,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
91
98
|
return new Queue(elements);
|
|
92
99
|
}
|
|
93
100
|
/**
|
|
94
|
-
* Time Complexity: O(1)
|
|
95
|
-
* Space Complexity: O(1)
|
|
101
|
+
* Time Complexity: O(1)
|
|
102
|
+
* Space Complexity: O(1)
|
|
96
103
|
*/
|
|
97
104
|
/**
|
|
98
|
-
* Time Complexity: O(1)
|
|
99
|
-
* Space Complexity: O(1)
|
|
105
|
+
* Time Complexity: O(1)
|
|
106
|
+
* Space Complexity: O(1)
|
|
100
107
|
*
|
|
101
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.
|
|
102
109
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
@@ -107,12 +114,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
107
114
|
return true;
|
|
108
115
|
}
|
|
109
116
|
/**
|
|
110
|
-
* Time Complexity: O(1)
|
|
111
|
-
* Space Complexity: O(1)
|
|
117
|
+
* Time Complexity: O(1)
|
|
118
|
+
* Space Complexity: O(1)
|
|
112
119
|
*/
|
|
113
120
|
/**
|
|
114
|
-
* Time Complexity: O(
|
|
115
|
-
* Space Complexity: O(1)
|
|
121
|
+
* Time Complexity: O(1)
|
|
122
|
+
* Space Complexity: O(1)
|
|
116
123
|
*
|
|
117
124
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
118
125
|
* necessary to optimize performance.
|
|
@@ -150,12 +157,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
150
157
|
return spliced.length === 1;
|
|
151
158
|
}
|
|
152
159
|
/**
|
|
153
|
-
* Time Complexity: O(1)
|
|
154
|
-
* Space Complexity: O(1)
|
|
160
|
+
* Time Complexity: O(1)
|
|
161
|
+
* Space Complexity: O(1)
|
|
155
162
|
*/
|
|
156
163
|
/**
|
|
157
|
-
* Time Complexity: O(1)
|
|
158
|
-
* Space Complexity: O(1)
|
|
164
|
+
* Time Complexity: O(1)
|
|
165
|
+
* Space Complexity: O(1)
|
|
159
166
|
*
|
|
160
167
|
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
161
168
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -165,12 +172,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
165
172
|
return this.first;
|
|
166
173
|
}
|
|
167
174
|
/**
|
|
168
|
-
* Time Complexity: O(1)
|
|
169
|
-
* Space Complexity: O(1)
|
|
175
|
+
* Time Complexity: O(1)
|
|
176
|
+
* Space Complexity: O(1)
|
|
170
177
|
*/
|
|
171
178
|
/**
|
|
172
|
-
* Time Complexity: O(1)
|
|
173
|
-
* Space Complexity: O(1)
|
|
179
|
+
* Time Complexity: O(1)
|
|
180
|
+
* Space Complexity: O(1)
|
|
174
181
|
*
|
|
175
182
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
176
183
|
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -180,12 +187,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
180
187
|
return this.last;
|
|
181
188
|
}
|
|
182
189
|
/**
|
|
183
|
-
* Time Complexity: O(1)
|
|
184
|
-
* Space Complexity: O(1)
|
|
190
|
+
* Time Complexity: O(1)
|
|
191
|
+
* Space Complexity: O(1)
|
|
185
192
|
*/
|
|
186
193
|
/**
|
|
187
|
-
* Time Complexity: O(1)
|
|
188
|
-
* Space Complexity: O(1)
|
|
194
|
+
* Time Complexity: O(1)
|
|
195
|
+
* Space Complexity: O(1)
|
|
189
196
|
*
|
|
190
197
|
* The enqueue function adds a value to the end of a queue.
|
|
191
198
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -194,12 +201,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
194
201
|
return this.push(value);
|
|
195
202
|
}
|
|
196
203
|
/**
|
|
197
|
-
* Time Complexity: O(
|
|
198
|
-
* Space Complexity: O(1)
|
|
204
|
+
* Time Complexity: O(1)
|
|
205
|
+
* Space Complexity: O(1)
|
|
199
206
|
*/
|
|
200
207
|
/**
|
|
201
|
-
* Time Complexity: O(
|
|
202
|
-
* Space Complexity: O(1)
|
|
208
|
+
* Time Complexity: O(1)
|
|
209
|
+
* Space Complexity: O(1)
|
|
203
210
|
*
|
|
204
211
|
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
205
212
|
* @returns The method is returning a value of type E or undefined.
|
|
@@ -208,12 +215,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
208
215
|
return this.shift();
|
|
209
216
|
}
|
|
210
217
|
/**
|
|
211
|
-
* Time Complexity: O(1)
|
|
212
|
-
* Space Complexity: O(1)
|
|
218
|
+
* Time Complexity: O(1)
|
|
219
|
+
* Space Complexity: O(1)
|
|
213
220
|
*/
|
|
214
221
|
/**
|
|
215
|
-
* Time Complexity: O(1)
|
|
216
|
-
* Space Complexity: O(1)
|
|
222
|
+
* Time Complexity: O(1)
|
|
223
|
+
* Space Complexity: O(1)
|
|
217
224
|
*
|
|
218
225
|
* @param index
|
|
219
226
|
*/
|
|
@@ -221,12 +228,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
221
228
|
return this.elements[index];
|
|
222
229
|
}
|
|
223
230
|
/**
|
|
224
|
-
* Time Complexity: O(1)
|
|
225
|
-
* Space Complexity: O(1)
|
|
231
|
+
* Time Complexity: O(1)
|
|
232
|
+
* Space Complexity: O(1)
|
|
226
233
|
*/
|
|
227
234
|
/**
|
|
228
|
-
* Time Complexity: O(1)
|
|
229
|
-
* Space Complexity: O(1)
|
|
235
|
+
* Time Complexity: O(1)
|
|
236
|
+
* Space Complexity: O(1)
|
|
230
237
|
*
|
|
231
238
|
* The function checks if a data structure is empty by comparing its size to zero.
|
|
232
239
|
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
@@ -235,12 +242,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
235
242
|
return this.size === 0;
|
|
236
243
|
}
|
|
237
244
|
/**
|
|
238
|
-
* Time Complexity: O(1)
|
|
239
|
-
* Space Complexity: O(n)
|
|
245
|
+
* Time Complexity: O(1)
|
|
246
|
+
* Space Complexity: O(n)
|
|
240
247
|
*/
|
|
241
248
|
/**
|
|
242
|
-
* Time Complexity: O(1)
|
|
243
|
-
* Space Complexity: O(n)
|
|
249
|
+
* Time Complexity: O(1)
|
|
250
|
+
* Space Complexity: O(n)
|
|
244
251
|
*
|
|
245
252
|
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
246
253
|
* @returns An array of type E is being returned.
|
|
@@ -249,6 +256,13 @@ class Queue extends base_1.IterableElementBase {
|
|
|
249
256
|
return this.elements.slice(this.offset);
|
|
250
257
|
}
|
|
251
258
|
/**
|
|
259
|
+
* Time Complexity: O(1)
|
|
260
|
+
* Space Complexity: O(1)
|
|
261
|
+
*/
|
|
262
|
+
/**
|
|
263
|
+
* Time Complexity: O(1)
|
|
264
|
+
* Space Complexity: O(1)
|
|
265
|
+
*
|
|
252
266
|
* The clear function resets the elements array and offset to their initial values.
|
|
253
267
|
*/
|
|
254
268
|
clear() {
|
|
@@ -332,6 +346,12 @@ class Queue extends base_1.IterableElementBase {
|
|
|
332
346
|
* Time Complexity: O(n)
|
|
333
347
|
* Space Complexity: O(n)
|
|
334
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
|
+
*/
|
|
335
355
|
*_getIterator() {
|
|
336
356
|
for (const item of this.elements) {
|
|
337
357
|
yield item;
|
|
@@ -29,18 +29,18 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
|
|
|
29
29
|
* @return An array of elements
|
|
30
30
|
*/
|
|
31
31
|
get elements(): E[];
|
|
32
|
-
/**
|
|
33
|
-
* Time Complexity: O(n), where n is the number of elements in the input array. Similar to the constructor, it requires iterating through each element.
|
|
34
|
-
* Space Complexity: O(n), as it creates a new stack with the elements from the input array.
|
|
35
|
-
*/
|
|
36
32
|
/**
|
|
37
33
|
* The size() function returns the number of elements in an array.
|
|
38
34
|
* @returns The size of the elements array.
|
|
39
35
|
*/
|
|
40
36
|
get size(): number;
|
|
41
37
|
/**
|
|
42
|
-
* Time Complexity: O(n)
|
|
43
|
-
* Space Complexity: O(n)
|
|
38
|
+
* Time Complexity: O(n)
|
|
39
|
+
* Space Complexity: O(n)
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Time Complexity: O(n)
|
|
43
|
+
* Space Complexity: O(n)
|
|
44
44
|
*
|
|
45
45
|
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
46
46
|
* @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
|
|
@@ -54,24 +54,24 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
|
|
|
54
54
|
*/
|
|
55
55
|
isEmpty(): boolean;
|
|
56
56
|
/**
|
|
57
|
-
* Time Complexity: O(1)
|
|
58
|
-
* Space Complexity: O(1)
|
|
57
|
+
* Time Complexity: O(1)
|
|
58
|
+
* Space Complexity: O(1)
|
|
59
59
|
*/
|
|
60
60
|
/**
|
|
61
|
-
* Time Complexity: O(1)
|
|
62
|
-
* Space Complexity: O(1)
|
|
61
|
+
* Time Complexity: O(1)
|
|
62
|
+
* Space Complexity: O(1)
|
|
63
63
|
*
|
|
64
64
|
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
65
65
|
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
66
66
|
*/
|
|
67
67
|
peek(): E | undefined;
|
|
68
68
|
/**
|
|
69
|
-
* Time Complexity: O(1)
|
|
70
|
-
* Space Complexity: O(1)
|
|
69
|
+
* Time Complexity: O(1)
|
|
70
|
+
* Space Complexity: O(1)
|
|
71
71
|
*/
|
|
72
72
|
/**
|
|
73
|
-
* Time Complexity: O(1)
|
|
74
|
-
* Space Complexity: O(1)
|
|
73
|
+
* Time Complexity: O(1)
|
|
74
|
+
* Space Complexity: O(1)
|
|
75
75
|
*
|
|
76
76
|
* The push function adds an element to the stack and returns the updated stack.
|
|
77
77
|
* @param {E} element - The parameter "element" is of type E, which means it can be any data type.
|
|
@@ -79,12 +79,12 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
|
|
|
79
79
|
*/
|
|
80
80
|
push(element: E): boolean;
|
|
81
81
|
/**
|
|
82
|
-
* Time Complexity: O(1)
|
|
83
|
-
* Space Complexity: O(1)
|
|
82
|
+
* Time Complexity: O(1)
|
|
83
|
+
* Space Complexity: O(1)
|
|
84
84
|
*/
|
|
85
85
|
/**
|
|
86
|
-
* Time Complexity: O(1)
|
|
87
|
-
* Space Complexity: O(1)
|
|
86
|
+
* Time Complexity: O(1)
|
|
87
|
+
* Space Complexity: O(1)
|
|
88
88
|
*
|
|
89
89
|
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
90
90
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
@@ -116,16 +116,23 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
|
|
|
116
116
|
*/
|
|
117
117
|
toArray(): E[];
|
|
118
118
|
/**
|
|
119
|
+
* Time Complexity: O(1)
|
|
120
|
+
* Space Complexity: O(1)
|
|
121
|
+
*/
|
|
122
|
+
/**
|
|
123
|
+
* Time Complexity: O(1)
|
|
124
|
+
* Space Complexity: O(1)
|
|
125
|
+
*
|
|
119
126
|
* The clear function clears the elements array.
|
|
120
127
|
*/
|
|
121
128
|
clear(): void;
|
|
122
129
|
/**
|
|
123
|
-
* Time Complexity: O(n)
|
|
124
|
-
* Space Complexity: O(n)
|
|
130
|
+
* Time Complexity: O(n)
|
|
131
|
+
* Space Complexity: O(n)
|
|
125
132
|
*/
|
|
126
133
|
/**
|
|
127
|
-
* Time Complexity: O(n)
|
|
128
|
-
* Space Complexity: O(n)
|
|
134
|
+
* Time Complexity: O(n)
|
|
135
|
+
* Space Complexity: O(n)
|
|
129
136
|
*
|
|
130
137
|
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
131
138
|
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
@@ -171,6 +178,13 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
|
|
|
171
178
|
*/
|
|
172
179
|
map<T>(callback: ElementCallback<E, T>, thisArg?: any): Stack<T>;
|
|
173
180
|
/**
|
|
181
|
+
* Time Complexity: O(n)
|
|
182
|
+
* Space Complexity: O(n)
|
|
183
|
+
*/
|
|
184
|
+
/**
|
|
185
|
+
* Time Complexity: O(n)
|
|
186
|
+
* Space Complexity: O(n)
|
|
187
|
+
*
|
|
174
188
|
* Custom iterator for the Stack class.
|
|
175
189
|
* @returns An iterator object.
|
|
176
190
|
*/
|