queue-typed 1.49.1 → 1.49.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/data-structures/base/iterable-base.js +21 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +7 -7
- package/dist/data-structures/graph/abstract-graph.js +43 -12
- package/dist/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/data-structures/graph/directed-graph.js +2 -2
- package/dist/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/data-structures/graph/undirected-graph.js +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +9 -9
- package/dist/data-structures/hash/hash-map.js +16 -15
- package/dist/data-structures/heap/heap.d.ts +6 -35
- package/dist/data-structures/heap/heap.js +10 -42
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
- package/dist/data-structures/linked-list/doubly-linked-list.js +143 -146
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +16 -21
- package/dist/data-structures/linked-list/singly-linked-list.js +42 -42
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/data-structures/queue/deque.d.ts +70 -75
- package/dist/data-structures/queue/deque.js +100 -110
- package/dist/data-structures/queue/queue.d.ts +37 -38
- package/dist/data-structures/queue/queue.js +46 -49
- package/dist/data-structures/stack/stack.d.ts +2 -3
- package/dist/data-structures/stack/stack.js +2 -5
- package/dist/data-structures/trie/trie.d.ts +1 -2
- package/dist/data-structures/trie/trie.js +2 -5
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +24 -0
- package/src/data-structures/graph/abstract-graph.ts +55 -14
- package/src/data-structures/graph/directed-graph.ts +3 -2
- package/src/data-structures/graph/undirected-graph.ts +1 -1
- package/src/data-structures/hash/hash-map.ts +27 -28
- package/src/data-structures/heap/heap.ts +19 -57
- package/src/data-structures/linked-list/doubly-linked-list.ts +157 -161
- package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/deque.ts +122 -135
- package/src/data-structures/queue/queue.ts +54 -58
- package/src/data-structures/stack/stack.ts +4 -8
- package/src/data-structures/trie/trie.ts +5 -9
|
@@ -26,54 +26,53 @@ export declare class DoublyLinkedListNode<E = any> {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
28
28
|
/**
|
|
29
|
-
* The constructor initializes the linked list with an empty head, tail, and
|
|
29
|
+
* The constructor initializes the linked list with an empty head, tail, and size.
|
|
30
30
|
*/
|
|
31
31
|
constructor(elements?: Iterable<E>);
|
|
32
32
|
protected _head: DoublyLinkedListNode<E> | undefined;
|
|
33
33
|
get head(): DoublyLinkedListNode<E> | undefined;
|
|
34
34
|
protected _tail: DoublyLinkedListNode<E> | undefined;
|
|
35
35
|
get tail(): DoublyLinkedListNode<E> | undefined;
|
|
36
|
-
protected
|
|
37
|
-
get length(): number;
|
|
36
|
+
protected _size: number;
|
|
38
37
|
get size(): number;
|
|
39
38
|
/**
|
|
40
|
-
* Time Complexity: O(n), where n is the
|
|
39
|
+
* Time Complexity: O(n), where n is the size of the input array.
|
|
41
40
|
* Space Complexity: O(n)
|
|
42
41
|
*/
|
|
43
42
|
/**
|
|
44
|
-
* Time Complexity: O(n), where n is the
|
|
45
|
-
* Space Complexity: O(
|
|
43
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
44
|
+
* Space Complexity: O(1)
|
|
46
45
|
*
|
|
47
|
-
* The `
|
|
48
|
-
*
|
|
49
|
-
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
50
|
-
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
46
|
+
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
47
|
+
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
51
48
|
*/
|
|
52
|
-
|
|
49
|
+
get first(): E | undefined;
|
|
53
50
|
/**
|
|
54
51
|
* Time Complexity: O(1)
|
|
55
52
|
* Space Complexity: O(1)
|
|
56
53
|
*/
|
|
57
54
|
/**
|
|
58
|
-
* Time Complexity: O(
|
|
55
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
59
56
|
* Space Complexity: O(1)
|
|
60
57
|
*
|
|
61
|
-
* The
|
|
62
|
-
* @
|
|
58
|
+
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
59
|
+
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
63
60
|
*/
|
|
64
|
-
|
|
61
|
+
get last(): E | undefined;
|
|
65
62
|
/**
|
|
66
63
|
* Time Complexity: O(1)
|
|
67
64
|
* Space Complexity: O(1)
|
|
68
65
|
*/
|
|
69
66
|
/**
|
|
70
|
-
* Time Complexity: O(
|
|
71
|
-
* Space Complexity: O(
|
|
67
|
+
* Time Complexity: O(n), where n is the size of the input array.
|
|
68
|
+
* Space Complexity: O(n)
|
|
72
69
|
*
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
70
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
71
|
+
* given array.
|
|
72
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
73
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
75
74
|
*/
|
|
76
|
-
|
|
75
|
+
static fromArray<E>(data: E[]): DoublyLinkedList<E>;
|
|
77
76
|
/**
|
|
78
77
|
* Time Complexity: O(1)
|
|
79
78
|
* Space Complexity: O(1)
|
|
@@ -82,11 +81,10 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
82
81
|
* Time Complexity: O(1)
|
|
83
82
|
* Space Complexity: O(1)
|
|
84
83
|
*
|
|
85
|
-
* The
|
|
86
|
-
* @
|
|
87
|
-
* list is empty, it returns undefined.
|
|
84
|
+
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
85
|
+
* @param {E} value - The value to be added to the linked list.
|
|
88
86
|
*/
|
|
89
|
-
|
|
87
|
+
push(value: E): boolean;
|
|
90
88
|
/**
|
|
91
89
|
* Time Complexity: O(1)
|
|
92
90
|
* Space Complexity: O(1)
|
|
@@ -95,13 +93,13 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
95
93
|
* Time Complexity: O(1)
|
|
96
94
|
* Space Complexity: O(1)
|
|
97
95
|
*
|
|
98
|
-
* The `
|
|
96
|
+
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
99
97
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
100
98
|
* list is empty, it returns undefined.
|
|
101
99
|
*/
|
|
102
|
-
|
|
100
|
+
pop(): E | undefined;
|
|
103
101
|
/**
|
|
104
|
-
* Time Complexity: O(
|
|
102
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
105
103
|
* Space Complexity: O(1)
|
|
106
104
|
*/
|
|
107
105
|
/**
|
|
@@ -114,20 +112,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
114
112
|
*/
|
|
115
113
|
shift(): E | undefined;
|
|
116
114
|
/**
|
|
117
|
-
* Time Complexity: O(
|
|
118
|
-
* Space Complexity: O(1)
|
|
119
|
-
*/
|
|
120
|
-
/**
|
|
121
|
-
* Time Complexity: O(1)
|
|
122
|
-
* Space Complexity: O(1)
|
|
123
|
-
*
|
|
124
|
-
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
125
|
-
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
126
|
-
* list.
|
|
127
|
-
*/
|
|
128
|
-
pollFirst(): E | undefined;
|
|
129
|
-
/**
|
|
130
|
-
* Time Complexity: O(1)
|
|
115
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
131
116
|
* Space Complexity: O(1)
|
|
132
117
|
*/
|
|
133
118
|
/**
|
|
@@ -138,44 +123,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
138
123
|
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
139
124
|
* doubly linked list.
|
|
140
125
|
*/
|
|
141
|
-
unshift(value: E):
|
|
142
|
-
/**
|
|
143
|
-
* Time Complexity: O(1)
|
|
144
|
-
* Space Complexity: O(1)
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* Time Complexity: O(1)
|
|
148
|
-
* Space Complexity: O(1)
|
|
149
|
-
*
|
|
150
|
-
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
151
|
-
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
152
|
-
* doubly linked list.
|
|
153
|
-
*/
|
|
154
|
-
addFirst(value: E): void;
|
|
155
|
-
/**
|
|
156
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
157
|
-
* Space Complexity: O(1)
|
|
158
|
-
*/
|
|
159
|
-
/**
|
|
160
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
161
|
-
* Space Complexity: O(1)
|
|
162
|
-
*
|
|
163
|
-
* The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
164
|
-
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
165
|
-
*/
|
|
166
|
-
getFirst(): E | undefined;
|
|
167
|
-
/**
|
|
168
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
169
|
-
* Space Complexity: O(1)
|
|
170
|
-
*/
|
|
171
|
-
/**
|
|
172
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
173
|
-
* Space Complexity: O(1)
|
|
174
|
-
*
|
|
175
|
-
* The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
176
|
-
* @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
177
|
-
*/
|
|
178
|
-
getLast(): E | undefined;
|
|
126
|
+
unshift(value: E): boolean;
|
|
179
127
|
/**
|
|
180
128
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
181
129
|
* Space Complexity: O(1)
|
|
@@ -238,7 +186,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
238
186
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
239
187
|
* if the index is out of bounds.
|
|
240
188
|
*/
|
|
241
|
-
|
|
189
|
+
addAt(index: number, value: E): boolean;
|
|
242
190
|
/**
|
|
243
191
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
244
192
|
* Space Complexity: O(1)
|
|
@@ -247,7 +195,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
247
195
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
248
196
|
* Space Complexity: O(1)
|
|
249
197
|
*
|
|
250
|
-
* The `
|
|
198
|
+
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
251
199
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
252
200
|
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
253
201
|
* itself.
|
|
@@ -256,7 +204,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
256
204
|
* @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
257
205
|
* insertion fails.
|
|
258
206
|
*/
|
|
259
|
-
|
|
207
|
+
addBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
260
208
|
/**
|
|
261
209
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
262
210
|
* Space Complexity: O(1)
|
|
@@ -265,7 +213,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
265
213
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
266
214
|
* Space Complexity: O(1)
|
|
267
215
|
*
|
|
268
|
-
* The `
|
|
216
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
269
217
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
270
218
|
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
271
219
|
* itself.
|
|
@@ -273,11 +221,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
273
221
|
* @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
|
|
274
222
|
* existing value or node is not found in the doubly linked list.
|
|
275
223
|
*/
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
279
|
-
* Space Complexity: O(1)
|
|
280
|
-
*/
|
|
224
|
+
addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
281
225
|
/**
|
|
282
226
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
283
227
|
* Space Complexity: O(1)
|
|
@@ -288,11 +232,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
288
232
|
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
289
233
|
* bounds.
|
|
290
234
|
*/
|
|
291
|
-
deleteAt(index: number):
|
|
292
|
-
/**
|
|
293
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
294
|
-
* Space Complexity: O(1)
|
|
295
|
-
*/
|
|
235
|
+
deleteAt(index: number): boolean;
|
|
296
236
|
/**
|
|
297
237
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
298
238
|
* Space Complexity: O(1)
|
|
@@ -305,12 +245,20 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
305
245
|
*/
|
|
306
246
|
delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
307
247
|
/**
|
|
308
|
-
*
|
|
248
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
249
|
+
* Space Complexity: O(1)
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
309
253
|
* @returns A boolean value is being returned.
|
|
310
254
|
*/
|
|
311
255
|
isEmpty(): boolean;
|
|
312
256
|
/**
|
|
313
|
-
*
|
|
257
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
258
|
+
* Space Complexity: O(1)
|
|
259
|
+
*/
|
|
260
|
+
/**
|
|
261
|
+
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
314
262
|
*/
|
|
315
263
|
clear(): void;
|
|
316
264
|
/**
|
|
@@ -345,7 +293,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
345
293
|
indexOf(value: E): number;
|
|
346
294
|
/**
|
|
347
295
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
348
|
-
* Space Complexity: O(
|
|
296
|
+
* Space Complexity: O(n)
|
|
349
297
|
*/
|
|
350
298
|
/**
|
|
351
299
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -361,7 +309,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
361
309
|
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
362
310
|
/**
|
|
363
311
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
364
|
-
* Space Complexity: O(
|
|
312
|
+
* Space Complexity: O(n)
|
|
365
313
|
*/
|
|
366
314
|
/**
|
|
367
315
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -369,9 +317,9 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
369
317
|
*
|
|
370
318
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
371
319
|
*/
|
|
372
|
-
reverse():
|
|
320
|
+
reverse(): this;
|
|
373
321
|
/**
|
|
374
|
-
* Time Complexity: O(n)
|
|
322
|
+
* Time Complexity: O(n)
|
|
375
323
|
* Space Complexity: O(n)
|
|
376
324
|
*/
|
|
377
325
|
/**
|
|
@@ -395,8 +343,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
395
343
|
*/
|
|
396
344
|
toReversedArray(): E[];
|
|
397
345
|
/**
|
|
398
|
-
* Time Complexity: O(
|
|
399
|
-
* Space Complexity: O(
|
|
346
|
+
* Time Complexity: O(1)
|
|
347
|
+
* Space Complexity: O(1)
|
|
400
348
|
*/
|
|
401
349
|
/**
|
|
402
350
|
* Time Complexity: O(n)
|
|
@@ -417,8 +365,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
417
365
|
*/
|
|
418
366
|
filter(callback: ElementCallback<E, boolean>, thisArg?: any): DoublyLinkedList<E>;
|
|
419
367
|
/**
|
|
420
|
-
* Time Complexity: O(
|
|
421
|
-
* Space Complexity: O(
|
|
368
|
+
* Time Complexity: O(1)
|
|
369
|
+
* Space Complexity: O(1)
|
|
422
370
|
*/
|
|
423
371
|
/**
|
|
424
372
|
* Time Complexity: O(n)
|
|
@@ -438,11 +386,57 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
438
386
|
* object.
|
|
439
387
|
*/
|
|
440
388
|
map<T>(callback: ElementCallback<E, T>, thisArg?: any): DoublyLinkedList<T>;
|
|
389
|
+
/**
|
|
390
|
+
* Time Complexity: O(1)
|
|
391
|
+
* Space Complexity: O(1)
|
|
392
|
+
*/
|
|
393
|
+
/**
|
|
394
|
+
* Time Complexity: O(1)
|
|
395
|
+
* Space Complexity: O(1)
|
|
396
|
+
*
|
|
397
|
+
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
398
|
+
* @param {E} value - The value to be added to the linked list.
|
|
399
|
+
*/
|
|
400
|
+
addLast(value: E): boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Time Complexity: O(1)
|
|
403
|
+
* Space Complexity: O(1)
|
|
404
|
+
*/
|
|
405
|
+
/**
|
|
406
|
+
* Time Complexity: O(1)
|
|
407
|
+
* Space Complexity: O(1)
|
|
408
|
+
*
|
|
409
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
410
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
411
|
+
* list is empty, it returns undefined.
|
|
412
|
+
*/
|
|
413
|
+
pollLast(): E | undefined;
|
|
441
414
|
/**
|
|
442
415
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
443
|
-
* Space Complexity: O(
|
|
416
|
+
* Space Complexity: O(1)
|
|
444
417
|
*/
|
|
445
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Time Complexity: O(1)
|
|
420
|
+
* Space Complexity: O(1)
|
|
421
|
+
*
|
|
422
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
423
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
424
|
+
* list.
|
|
425
|
+
*/
|
|
426
|
+
pollFirst(): E | undefined;
|
|
427
|
+
/**
|
|
428
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
429
|
+
* Space Complexity: O(1)
|
|
430
|
+
*/
|
|
431
|
+
/**
|
|
432
|
+
* Time Complexity: O(1)
|
|
433
|
+
* Space Complexity: O(1)
|
|
434
|
+
*
|
|
435
|
+
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
436
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
437
|
+
* doubly linked list.
|
|
438
|
+
*/
|
|
439
|
+
addFirst(value: E): void;
|
|
446
440
|
/**
|
|
447
441
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
448
442
|
*/
|