min-heap-typed 1.50.2 → 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.
- package/dist/data-structures/base/iterable-base.d.ts +6 -0
- 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 +46 -13
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +73 -15
- 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-multimap.d.ts +35 -2
- package/dist/data-structures/binary-tree/tree-multimap.js +38 -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/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +12 -0
- 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 +46 -13
- package/src/data-structures/binary-tree/rb-tree.ts +79 -18
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +42 -3
- 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
|
@@ -51,7 +51,6 @@ class Heap extends base_1.IterableElementBase {
|
|
|
51
51
|
for (const el of elements) {
|
|
52
52
|
this.add(el);
|
|
53
53
|
}
|
|
54
|
-
// this.fix();
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
/**
|
|
@@ -130,6 +129,10 @@ class Heap extends base_1.IterableElementBase {
|
|
|
130
129
|
}
|
|
131
130
|
return value;
|
|
132
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Time Complexity: O(1)
|
|
134
|
+
* Space Complexity: O(1)
|
|
135
|
+
*/
|
|
133
136
|
/**
|
|
134
137
|
* Time Complexity: O(1)
|
|
135
138
|
* Space Complexity: O(1)
|
|
@@ -154,11 +157,11 @@ class Heap extends base_1.IterableElementBase {
|
|
|
154
157
|
this._elements = [];
|
|
155
158
|
}
|
|
156
159
|
/**
|
|
157
|
-
* Time Complexity: O(n)
|
|
160
|
+
* Time Complexity: O(n)
|
|
158
161
|
* Space Complexity: O(n)
|
|
159
162
|
*/
|
|
160
163
|
/**
|
|
161
|
-
* Time Complexity: O(n)
|
|
164
|
+
* Time Complexity: O(n)
|
|
162
165
|
* Space Complexity: O(n)
|
|
163
166
|
*
|
|
164
167
|
* Clear and add elements of the heap
|
|
@@ -169,11 +172,11 @@ class Heap extends base_1.IterableElementBase {
|
|
|
169
172
|
return this.fix();
|
|
170
173
|
}
|
|
171
174
|
/**
|
|
172
|
-
* Time Complexity: O(n)
|
|
175
|
+
* Time Complexity: O(n)
|
|
173
176
|
* Space Complexity: O(1)
|
|
174
177
|
*/
|
|
175
178
|
/**
|
|
176
|
-
* Time Complexity: O(n)
|
|
179
|
+
* Time Complexity: O(n)
|
|
177
180
|
* Space Complexity: O(1)
|
|
178
181
|
*
|
|
179
182
|
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
@@ -184,11 +187,12 @@ class Heap extends base_1.IterableElementBase {
|
|
|
184
187
|
return this.elements.includes(element);
|
|
185
188
|
}
|
|
186
189
|
/**
|
|
187
|
-
* Time Complexity: O(n)
|
|
190
|
+
* Time Complexity: O(n)
|
|
188
191
|
* Space Complexity: O(1)
|
|
192
|
+
* The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
|
|
189
193
|
*/
|
|
190
194
|
/**
|
|
191
|
-
* Time Complexity: O(n)
|
|
195
|
+
* Time Complexity: O(n)
|
|
192
196
|
* Space Complexity: O(1)
|
|
193
197
|
*
|
|
194
198
|
* The `delete` function removes an element from an array-like data structure, maintaining the order
|
|
@@ -216,12 +220,13 @@ class Heap extends base_1.IterableElementBase {
|
|
|
216
220
|
return true;
|
|
217
221
|
}
|
|
218
222
|
/**
|
|
219
|
-
* Time Complexity: O(n)
|
|
220
|
-
* Space Complexity: O(
|
|
223
|
+
* Time Complexity: O(n)
|
|
224
|
+
* Space Complexity: O(log n)
|
|
225
|
+
* where log n is the height of the heap.
|
|
221
226
|
*/
|
|
222
227
|
/**
|
|
223
|
-
* Time Complexity: O(n)
|
|
224
|
-
* Space Complexity: O(
|
|
228
|
+
* Time Complexity: O(n)
|
|
229
|
+
* Space Complexity: O(log n)
|
|
225
230
|
*
|
|
226
231
|
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
227
232
|
* @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
@@ -305,12 +310,12 @@ class Heap extends base_1.IterableElementBase {
|
|
|
305
310
|
return visitedNode;
|
|
306
311
|
}
|
|
307
312
|
/**
|
|
308
|
-
* Time Complexity: O(log n)
|
|
309
|
-
* Space Complexity: O(
|
|
313
|
+
* Time Complexity: O(n log n)
|
|
314
|
+
* Space Complexity: O(n)
|
|
310
315
|
*/
|
|
311
316
|
/**
|
|
312
|
-
* Time Complexity: O(n)
|
|
313
|
-
* Space Complexity: O(
|
|
317
|
+
* Time Complexity: O(n log n)
|
|
318
|
+
* Space Complexity: O(n)
|
|
314
319
|
*
|
|
315
320
|
* Fix the entire heap to maintain heap properties.
|
|
316
321
|
*/
|
|
@@ -393,7 +398,7 @@ class Heap extends base_1.IterableElementBase {
|
|
|
393
398
|
}
|
|
394
399
|
}
|
|
395
400
|
/**
|
|
396
|
-
* Time Complexity: O(n)
|
|
401
|
+
* Time Complexity: O(log n)
|
|
397
402
|
* Space Complexity: O(1)
|
|
398
403
|
*/
|
|
399
404
|
/**
|
|
@@ -416,6 +421,10 @@ class Heap extends base_1.IterableElementBase {
|
|
|
416
421
|
this.elements[index] = element;
|
|
417
422
|
return true;
|
|
418
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Time Complexity: O(log n)
|
|
426
|
+
* Space Complexity: O(1)
|
|
427
|
+
*/
|
|
419
428
|
/**
|
|
420
429
|
* Time Complexity: O(log n)
|
|
421
430
|
* Space Complexity: O(1)
|
|
@@ -619,11 +628,11 @@ class FibonacciHeap {
|
|
|
619
628
|
}
|
|
620
629
|
}
|
|
621
630
|
/**
|
|
622
|
-
* Time Complexity: O(log n)
|
|
631
|
+
* Time Complexity: O(log n)
|
|
623
632
|
* Space Complexity: O(1)
|
|
624
633
|
*/
|
|
625
634
|
/**
|
|
626
|
-
* Time Complexity: O(log n)
|
|
635
|
+
* Time Complexity: O(log n)
|
|
627
636
|
* Space Complexity: O(1)
|
|
628
637
|
*
|
|
629
638
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -633,11 +642,11 @@ class FibonacciHeap {
|
|
|
633
642
|
return this.pop();
|
|
634
643
|
}
|
|
635
644
|
/**
|
|
636
|
-
* Time Complexity: O(log n)
|
|
645
|
+
* Time Complexity: O(log n)
|
|
637
646
|
* Space Complexity: O(1)
|
|
638
647
|
*/
|
|
639
648
|
/**
|
|
640
|
-
* Time Complexity: O(log n)
|
|
649
|
+
* Time Complexity: O(log n)
|
|
641
650
|
* Space Complexity: O(1)
|
|
642
651
|
*
|
|
643
652
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -8,15 +8,51 @@
|
|
|
8
8
|
import type { ElementCallback } from '../../types';
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
export declare class DoublyLinkedListNode<E = any> {
|
|
11
|
-
value: E;
|
|
12
|
-
next: DoublyLinkedListNode<E> | undefined;
|
|
13
|
-
prev: DoublyLinkedListNode<E> | undefined;
|
|
14
11
|
/**
|
|
15
12
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
16
13
|
* @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
17
14
|
* is defined as a generic type "E".
|
|
18
15
|
*/
|
|
19
16
|
constructor(value: E);
|
|
17
|
+
protected _value: E;
|
|
18
|
+
/**
|
|
19
|
+
* The function returns the value of a protected variable.
|
|
20
|
+
* @returns The value of the variable `_value` is being returned.
|
|
21
|
+
*/
|
|
22
|
+
get value(): E;
|
|
23
|
+
/**
|
|
24
|
+
* The above function sets the value of a variable.
|
|
25
|
+
* @param {E} value - The parameter "value" is of type E, which means it can be any type.
|
|
26
|
+
*/
|
|
27
|
+
set value(value: E);
|
|
28
|
+
protected _next: DoublyLinkedListNode<E> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The "next" function returns the next node in a doubly linked list.
|
|
31
|
+
* @returns The `next` property is being returned. It can be either a `DoublyLinkedListNode<E>`
|
|
32
|
+
* object or `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
get next(): DoublyLinkedListNode<E> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The "next" property of a DoublyLinkedListNode is set to the provided value.
|
|
37
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
38
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
39
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
40
|
+
*/
|
|
41
|
+
set next(value: DoublyLinkedListNode<E> | undefined);
|
|
42
|
+
protected _prev: DoublyLinkedListNode<E> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The `prev` function returns the previous node in a doubly linked list.
|
|
45
|
+
* @returns The `prev` property of the `DoublyLinkedListNode` class is being returned. It can either
|
|
46
|
+
* be a `DoublyLinkedListNode` object or `undefined`.
|
|
47
|
+
*/
|
|
48
|
+
get prev(): DoublyLinkedListNode<E> | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The function sets the previous node of a doubly linked list node.
|
|
51
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
52
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
53
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
54
|
+
*/
|
|
55
|
+
set prev(value: DoublyLinkedListNode<E> | undefined);
|
|
20
56
|
}
|
|
21
57
|
/**
|
|
22
58
|
* 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
|
|
@@ -52,12 +88,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
52
88
|
*/
|
|
53
89
|
get size(): number;
|
|
54
90
|
/**
|
|
55
|
-
* Time Complexity: O(
|
|
56
|
-
* Space Complexity: O(
|
|
91
|
+
* Time Complexity: O(1)
|
|
92
|
+
* Space Complexity: O(1)
|
|
57
93
|
* where n is the number of elements in the linked list.
|
|
58
94
|
*/
|
|
59
95
|
/**
|
|
60
|
-
* Time Complexity: O(
|
|
96
|
+
* Time Complexity: O(1)
|
|
61
97
|
* Space Complexity: O(1)
|
|
62
98
|
*
|
|
63
99
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -69,7 +105,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
69
105
|
* Space Complexity: O(1)
|
|
70
106
|
*/
|
|
71
107
|
/**
|
|
72
|
-
* Time Complexity: O(
|
|
108
|
+
* Time Complexity: O(1)
|
|
73
109
|
* Space Complexity: O(1)
|
|
74
110
|
*
|
|
75
111
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -77,11 +113,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
77
113
|
*/
|
|
78
114
|
get last(): E | undefined;
|
|
79
115
|
/**
|
|
80
|
-
* Time Complexity: O(
|
|
81
|
-
* Space Complexity: O(
|
|
116
|
+
* Time Complexity: O(n)
|
|
117
|
+
* Space Complexity: O(n)
|
|
82
118
|
*/
|
|
83
119
|
/**
|
|
84
|
-
* Time Complexity: O(n)
|
|
120
|
+
* Time Complexity: O(n)
|
|
85
121
|
* Space Complexity: O(n)
|
|
86
122
|
*
|
|
87
123
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
@@ -116,7 +152,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
116
152
|
*/
|
|
117
153
|
pop(): E | undefined;
|
|
118
154
|
/**
|
|
119
|
-
* Time Complexity: O(
|
|
155
|
+
* Time Complexity: O(1)
|
|
120
156
|
* Space Complexity: O(1)
|
|
121
157
|
*/
|
|
122
158
|
/**
|
|
@@ -129,7 +165,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
129
165
|
*/
|
|
130
166
|
shift(): E | undefined;
|
|
131
167
|
/**
|
|
132
|
-
* Time Complexity: O(
|
|
168
|
+
* Time Complexity: O(1)
|
|
133
169
|
* Space Complexity: O(1)
|
|
134
170
|
*/
|
|
135
171
|
/**
|
|
@@ -205,12 +241,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
205
241
|
*/
|
|
206
242
|
addAt(index: number, value: E): boolean;
|
|
207
243
|
/**
|
|
208
|
-
* Time Complexity: O(n)
|
|
244
|
+
* Time Complexity: O(1) or O(n)
|
|
209
245
|
* Space Complexity: O(1)
|
|
210
246
|
* where n is the number of elements in the linked list.
|
|
211
247
|
*/
|
|
212
248
|
/**
|
|
213
|
-
* Time Complexity: O(n)
|
|
249
|
+
* Time Complexity: O(1) or O(n)
|
|
214
250
|
* Space Complexity: O(1)
|
|
215
251
|
*
|
|
216
252
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -224,11 +260,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
224
260
|
*/
|
|
225
261
|
addBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
226
262
|
/**
|
|
227
|
-
* Time Complexity: O(n)
|
|
263
|
+
* Time Complexity: O(1) or O(n)
|
|
228
264
|
* Space Complexity: O(1)
|
|
229
265
|
*/
|
|
230
266
|
/**
|
|
231
|
-
* Time Complexity: O(n)
|
|
267
|
+
* Time Complexity: O(1) or O(n)
|
|
232
268
|
* Space Complexity: O(1)
|
|
233
269
|
*
|
|
234
270
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -252,7 +288,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
252
288
|
*/
|
|
253
289
|
deleteAt(index: number): boolean;
|
|
254
290
|
/**
|
|
255
|
-
* Time Complexity: O(n)
|
|
291
|
+
* Time Complexity: O(1) or O(n)
|
|
292
|
+
* Space Complexity: O(1)
|
|
293
|
+
*/
|
|
294
|
+
/**
|
|
295
|
+
* Time Complexity: O(1) or O(n)
|
|
256
296
|
* Space Complexity: O(1)
|
|
257
297
|
*
|
|
258
298
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -267,6 +307,9 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
267
307
|
* Space Complexity: O(1)
|
|
268
308
|
*/
|
|
269
309
|
/**
|
|
310
|
+
* Time Complexity: O(1)
|
|
311
|
+
* Space Complexity: O(1)
|
|
312
|
+
*
|
|
270
313
|
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
271
314
|
* @returns A boolean value is being returned.
|
|
272
315
|
*/
|
|
@@ -276,6 +319,9 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
276
319
|
* Space Complexity: O(1)
|
|
277
320
|
*/
|
|
278
321
|
/**
|
|
322
|
+
* Time Complexity: O(1)
|
|
323
|
+
* Space Complexity: O(1)
|
|
324
|
+
*
|
|
279
325
|
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
280
326
|
*/
|
|
281
327
|
clear(): void;
|
|
@@ -296,7 +342,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
296
342
|
indexOf(value: E): number;
|
|
297
343
|
/**
|
|
298
344
|
* Time Complexity: O(n)
|
|
299
|
-
* Space Complexity: O(
|
|
345
|
+
* Space Complexity: O(1)
|
|
300
346
|
*/
|
|
301
347
|
/**
|
|
302
348
|
* Time Complexity: O(n)
|
|
@@ -312,7 +358,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
312
358
|
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
313
359
|
/**
|
|
314
360
|
* Time Complexity: O(n)
|
|
315
|
-
* Space Complexity: O(
|
|
361
|
+
* Space Complexity: O(1)
|
|
316
362
|
*/
|
|
317
363
|
/**
|
|
318
364
|
* Time Complexity: O(n)
|
|
@@ -360,8 +406,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
360
406
|
*/
|
|
361
407
|
clone(): DoublyLinkedList<E>;
|
|
362
408
|
/**
|
|
363
|
-
* Time Complexity: O(
|
|
364
|
-
* Space Complexity: O(
|
|
409
|
+
* Time Complexity: O(n)
|
|
410
|
+
* Space Complexity: O(n)
|
|
365
411
|
*/
|
|
366
412
|
/**
|
|
367
413
|
* Time Complexity: O(n)
|
|
@@ -382,8 +428,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
382
428
|
*/
|
|
383
429
|
filter(callback: ElementCallback<E, boolean>, thisArg?: any): DoublyLinkedList<E>;
|
|
384
430
|
/**
|
|
385
|
-
* Time Complexity: O(
|
|
386
|
-
* Space Complexity: O(
|
|
431
|
+
* Time Complexity: O(n)
|
|
432
|
+
* Space Complexity: O(n)
|
|
387
433
|
*/
|
|
388
434
|
/**
|
|
389
435
|
* Time Complexity: O(n)
|
|
@@ -429,7 +475,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
429
475
|
*/
|
|
430
476
|
pollLast(): E | undefined;
|
|
431
477
|
/**
|
|
432
|
-
* Time Complexity: O(
|
|
478
|
+
* Time Complexity: O(1)
|
|
433
479
|
* Space Complexity: O(1)
|
|
434
480
|
*/
|
|
435
481
|
/**
|
|
@@ -442,7 +488,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
442
488
|
*/
|
|
443
489
|
pollFirst(): E | undefined;
|
|
444
490
|
/**
|
|
445
|
-
* Time Complexity: O(
|
|
491
|
+
* Time Complexity: O(1)
|
|
446
492
|
* Space Complexity: O(1)
|
|
447
493
|
*/
|
|
448
494
|
/**
|
|
@@ -9,9 +9,57 @@ class DoublyLinkedListNode {
|
|
|
9
9
|
* is defined as a generic type "E".
|
|
10
10
|
*/
|
|
11
11
|
constructor(value) {
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
12
|
+
this._value = value;
|
|
13
|
+
this._next = undefined;
|
|
14
|
+
this._prev = undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The function returns the value of a protected variable.
|
|
18
|
+
* @returns The value of the variable `_value` is being returned.
|
|
19
|
+
*/
|
|
20
|
+
get value() {
|
|
21
|
+
return this._value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The above function sets the value of a variable.
|
|
25
|
+
* @param {E} value - The parameter "value" is of type E, which means it can be any type.
|
|
26
|
+
*/
|
|
27
|
+
set value(value) {
|
|
28
|
+
this._value = value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The "next" function returns the next node in a doubly linked list.
|
|
32
|
+
* @returns The `next` property is being returned. It can be either a `DoublyLinkedListNode<E>`
|
|
33
|
+
* object or `undefined`.
|
|
34
|
+
*/
|
|
35
|
+
get next() {
|
|
36
|
+
return this._next;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The "next" property of a DoublyLinkedListNode is set to the provided value.
|
|
40
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
41
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
42
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
43
|
+
*/
|
|
44
|
+
set next(value) {
|
|
45
|
+
this._next = value;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The `prev` function returns the previous node in a doubly linked list.
|
|
49
|
+
* @returns The `prev` property of the `DoublyLinkedListNode` class is being returned. It can either
|
|
50
|
+
* be a `DoublyLinkedListNode` object or `undefined`.
|
|
51
|
+
*/
|
|
52
|
+
get prev() {
|
|
53
|
+
return this._prev;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The function sets the previous node of a doubly linked list node.
|
|
57
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
58
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
59
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
60
|
+
*/
|
|
61
|
+
set prev(value) {
|
|
62
|
+
this._prev = value;
|
|
15
63
|
}
|
|
16
64
|
}
|
|
17
65
|
exports.DoublyLinkedListNode = DoublyLinkedListNode;
|
|
@@ -62,12 +110,12 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
62
110
|
return this._size;
|
|
63
111
|
}
|
|
64
112
|
/**
|
|
65
|
-
* Time Complexity: O(
|
|
66
|
-
* Space Complexity: O(
|
|
113
|
+
* Time Complexity: O(1)
|
|
114
|
+
* Space Complexity: O(1)
|
|
67
115
|
* where n is the number of elements in the linked list.
|
|
68
116
|
*/
|
|
69
117
|
/**
|
|
70
|
-
* Time Complexity: O(
|
|
118
|
+
* Time Complexity: O(1)
|
|
71
119
|
* Space Complexity: O(1)
|
|
72
120
|
*
|
|
73
121
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -82,7 +130,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
82
130
|
* Space Complexity: O(1)
|
|
83
131
|
*/
|
|
84
132
|
/**
|
|
85
|
-
* Time Complexity: O(
|
|
133
|
+
* Time Complexity: O(1)
|
|
86
134
|
* Space Complexity: O(1)
|
|
87
135
|
*
|
|
88
136
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -93,11 +141,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
93
141
|
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
|
|
94
142
|
}
|
|
95
143
|
/**
|
|
96
|
-
* Time Complexity: O(
|
|
97
|
-
* Space Complexity: O(
|
|
144
|
+
* Time Complexity: O(n)
|
|
145
|
+
* Space Complexity: O(n)
|
|
98
146
|
*/
|
|
99
147
|
/**
|
|
100
|
-
* Time Complexity: O(n)
|
|
148
|
+
* Time Complexity: O(n)
|
|
101
149
|
* Space Complexity: O(n)
|
|
102
150
|
*
|
|
103
151
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
@@ -161,7 +209,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
161
209
|
return removedNode.value;
|
|
162
210
|
}
|
|
163
211
|
/**
|
|
164
|
-
* Time Complexity: O(
|
|
212
|
+
* Time Complexity: O(1)
|
|
165
213
|
* Space Complexity: O(1)
|
|
166
214
|
*/
|
|
167
215
|
/**
|
|
@@ -188,7 +236,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
188
236
|
return removedNode.value;
|
|
189
237
|
}
|
|
190
238
|
/**
|
|
191
|
-
* Time Complexity: O(
|
|
239
|
+
* Time Complexity: O(1)
|
|
192
240
|
* Space Complexity: O(1)
|
|
193
241
|
*/
|
|
194
242
|
/**
|
|
@@ -322,12 +370,12 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
322
370
|
return true;
|
|
323
371
|
}
|
|
324
372
|
/**
|
|
325
|
-
* Time Complexity: O(n)
|
|
373
|
+
* Time Complexity: O(1) or O(n)
|
|
326
374
|
* Space Complexity: O(1)
|
|
327
375
|
* where n is the number of elements in the linked list.
|
|
328
376
|
*/
|
|
329
377
|
/**
|
|
330
|
-
* Time Complexity: O(n)
|
|
378
|
+
* Time Complexity: O(1) or O(n)
|
|
331
379
|
* Space Complexity: O(1)
|
|
332
380
|
*
|
|
333
381
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -364,11 +412,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
364
412
|
return false;
|
|
365
413
|
}
|
|
366
414
|
/**
|
|
367
|
-
* Time Complexity: O(n)
|
|
415
|
+
* Time Complexity: O(1) or O(n)
|
|
368
416
|
* Space Complexity: O(1)
|
|
369
417
|
*/
|
|
370
418
|
/**
|
|
371
|
-
* Time Complexity: O(n)
|
|
419
|
+
* Time Complexity: O(1) or O(n)
|
|
372
420
|
* Space Complexity: O(1)
|
|
373
421
|
*
|
|
374
422
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -433,7 +481,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
433
481
|
return true;
|
|
434
482
|
}
|
|
435
483
|
/**
|
|
436
|
-
* Time Complexity: O(n)
|
|
484
|
+
* Time Complexity: O(1) or O(n)
|
|
485
|
+
* Space Complexity: O(1)
|
|
486
|
+
*/
|
|
487
|
+
/**
|
|
488
|
+
* Time Complexity: O(1) or O(n)
|
|
437
489
|
* Space Complexity: O(1)
|
|
438
490
|
*
|
|
439
491
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -473,6 +525,9 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
473
525
|
* Space Complexity: O(1)
|
|
474
526
|
*/
|
|
475
527
|
/**
|
|
528
|
+
* Time Complexity: O(1)
|
|
529
|
+
* Space Complexity: O(1)
|
|
530
|
+
*
|
|
476
531
|
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
477
532
|
* @returns A boolean value is being returned.
|
|
478
533
|
*/
|
|
@@ -484,6 +539,9 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
484
539
|
* Space Complexity: O(1)
|
|
485
540
|
*/
|
|
486
541
|
/**
|
|
542
|
+
* Time Complexity: O(1)
|
|
543
|
+
* Space Complexity: O(1)
|
|
544
|
+
*
|
|
487
545
|
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
488
546
|
*/
|
|
489
547
|
clear() {
|
|
@@ -519,7 +577,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
519
577
|
}
|
|
520
578
|
/**
|
|
521
579
|
* Time Complexity: O(n)
|
|
522
|
-
* Space Complexity: O(
|
|
580
|
+
* Space Complexity: O(1)
|
|
523
581
|
*/
|
|
524
582
|
/**
|
|
525
583
|
* Time Complexity: O(n)
|
|
@@ -544,7 +602,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
544
602
|
}
|
|
545
603
|
/**
|
|
546
604
|
* Time Complexity: O(n)
|
|
547
|
-
* Space Complexity: O(
|
|
605
|
+
* Space Complexity: O(1)
|
|
548
606
|
*/
|
|
549
607
|
/**
|
|
550
608
|
* Time Complexity: O(n)
|
|
@@ -619,8 +677,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
619
677
|
return new DoublyLinkedList(this.values());
|
|
620
678
|
}
|
|
621
679
|
/**
|
|
622
|
-
* Time Complexity: O(
|
|
623
|
-
* Space Complexity: O(
|
|
680
|
+
* Time Complexity: O(n)
|
|
681
|
+
* Space Complexity: O(n)
|
|
624
682
|
*/
|
|
625
683
|
/**
|
|
626
684
|
* Time Complexity: O(n)
|
|
@@ -651,8 +709,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
651
709
|
return filteredList;
|
|
652
710
|
}
|
|
653
711
|
/**
|
|
654
|
-
* Time Complexity: O(
|
|
655
|
-
* Space Complexity: O(
|
|
712
|
+
* Time Complexity: O(n)
|
|
713
|
+
* Space Complexity: O(n)
|
|
656
714
|
*/
|
|
657
715
|
/**
|
|
658
716
|
* Time Complexity: O(n)
|
|
@@ -710,7 +768,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
710
768
|
return this.pop();
|
|
711
769
|
}
|
|
712
770
|
/**
|
|
713
|
-
* Time Complexity: O(
|
|
771
|
+
* Time Complexity: O(1)
|
|
714
772
|
* Space Complexity: O(1)
|
|
715
773
|
*/
|
|
716
774
|
/**
|
|
@@ -725,7 +783,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
725
783
|
return this.shift();
|
|
726
784
|
}
|
|
727
785
|
/**
|
|
728
|
-
* Time Complexity: O(
|
|
786
|
+
* Time Complexity: O(1)
|
|
729
787
|
* Space Complexity: O(1)
|
|
730
788
|
*/
|
|
731
789
|
/**
|
|
@@ -8,14 +8,37 @@
|
|
|
8
8
|
import type { ElementCallback } from '../../types';
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
export declare class SinglyLinkedListNode<E = any> {
|
|
11
|
-
value: E;
|
|
12
|
-
next: SinglyLinkedListNode<E> | undefined;
|
|
13
11
|
/**
|
|
14
12
|
* The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
|
|
15
13
|
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
16
14
|
* will be stored in the node of a linked list.
|
|
17
15
|
*/
|
|
18
16
|
constructor(value: E);
|
|
17
|
+
protected _value: E;
|
|
18
|
+
/**
|
|
19
|
+
* The function returns the value of a protected variable.
|
|
20
|
+
* @returns The value of the variable `_value` is being returned.
|
|
21
|
+
*/
|
|
22
|
+
get value(): E;
|
|
23
|
+
/**
|
|
24
|
+
* The above function sets the value of a variable.
|
|
25
|
+
* @param {E} value - The parameter "value" is of type E, which means it can be any type.
|
|
26
|
+
*/
|
|
27
|
+
set value(value: E);
|
|
28
|
+
protected _next: SinglyLinkedListNode<E> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The `next` function returns the next node in a singly linked list.
|
|
31
|
+
* @returns The `next` property is being returned. It can be either a `SinglyLinkedListNode<E>`
|
|
32
|
+
* object or `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
get next(): SinglyLinkedListNode<E> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The "next" property of a SinglyLinkedListNode is set to the provided value.
|
|
37
|
+
* @param {SinglyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
38
|
+
* `SinglyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
39
|
+
* `SinglyLinkedListNode` object or `undefined` as its value.
|
|
40
|
+
*/
|
|
41
|
+
set next(value: SinglyLinkedListNode<E> | undefined);
|
|
19
42
|
}
|
|
20
43
|
export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
21
44
|
/**
|
|
@@ -391,7 +414,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
391
414
|
*/
|
|
392
415
|
filter(callback: ElementCallback<E, boolean>, thisArg?: any): SinglyLinkedList<E>;
|
|
393
416
|
/**
|
|
394
|
-
* Time Complexity: O(n)
|
|
417
|
+
* Time Complexity: O(n)
|
|
395
418
|
* Space Complexity: O(n)
|
|
396
419
|
*/
|
|
397
420
|
/**
|