min-heap-typed 1.49.2 → 1.49.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/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/graph/abstract-graph.d.ts +8 -17
- package/dist/data-structures/graph/abstract-graph.js +43 -29
- package/dist/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/data-structures/graph/directed-graph.js +6 -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/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/data-structures/linked-list/doubly-linked-list.js +49 -49
- 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/queue.d.ts +33 -33
- package/dist/data-structures/queue/queue.js +40 -40
- package/package.json +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/graph/abstract-graph.ts +56 -27
- package/src/data-structures/graph/directed-graph.ts +10 -5
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +53 -53
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/queue.ts +45 -45
|
@@ -525,7 +525,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
525
525
|
print(beginRoot?: BTNKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
|
|
526
526
|
protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
527
527
|
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
528
|
-
protected _defaultOneParamCallback: (node: N) => K;
|
|
528
|
+
protected _defaultOneParamCallback: (node: N | null | undefined) => K | undefined;
|
|
529
529
|
/**
|
|
530
530
|
* Swap the data of two nodes in the binary tree.
|
|
531
531
|
* @param {N} srcNode - The source node to swap.
|
|
@@ -80,7 +80,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
80
80
|
super();
|
|
81
81
|
this.iterationType = types_1.IterationType.ITERATIVE;
|
|
82
82
|
this._extractor = (key) => Number(key);
|
|
83
|
-
this._defaultOneParamCallback = (node) => node.key;
|
|
83
|
+
this._defaultOneParamCallback = (node) => node ? node.key : undefined;
|
|
84
84
|
if (options) {
|
|
85
85
|
const { iterationType, extractor } = options;
|
|
86
86
|
if (iterationType) {
|
|
@@ -99,16 +99,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
99
99
|
* Time Complexity: O(1) - Constant time for Map operations.
|
|
100
100
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
101
101
|
*/
|
|
102
|
-
|
|
103
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
104
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
105
|
-
*
|
|
106
|
-
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
107
|
-
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
108
|
-
* (`VertexKey`).
|
|
109
|
-
* @returns The method is returning a boolean value.
|
|
110
|
-
*/
|
|
111
|
-
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
102
|
+
abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
112
103
|
/**
|
|
113
104
|
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
114
105
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -432,11 +423,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
432
423
|
* type `number`.
|
|
433
424
|
*/
|
|
434
425
|
getLowMap(): Map<VO, number>;
|
|
435
|
-
/**
|
|
436
|
-
* The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
|
|
437
|
-
* @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
|
|
438
|
-
*/
|
|
439
|
-
getCycles(): Map<number, VO[]>;
|
|
440
426
|
/**
|
|
441
427
|
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
442
428
|
* @returns an array of VO objects, specifically the cut vertexes.
|
|
@@ -453,6 +439,11 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
453
439
|
* @returns the bridges found using the Tarjan algorithm.
|
|
454
440
|
*/
|
|
455
441
|
getBridges(): EO[];
|
|
442
|
+
/**
|
|
443
|
+
* O(V+E+C)
|
|
444
|
+
* O(V+C)
|
|
445
|
+
*/
|
|
446
|
+
getCycles(isInclude2Cycle?: boolean): VertexKey[][];
|
|
456
447
|
/**
|
|
457
448
|
* Time Complexity: O(n)
|
|
458
449
|
* Space Complexity: O(n)
|
|
@@ -493,8 +484,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
493
484
|
*/
|
|
494
485
|
map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
|
|
495
486
|
protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
|
|
496
|
-
protected abstract
|
|
497
|
-
protected
|
|
487
|
+
protected abstract _addEdge(edge: EO): boolean;
|
|
488
|
+
protected _addVertex(newVertex: VO): boolean;
|
|
498
489
|
protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
|
|
499
490
|
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
|
|
500
491
|
}
|
|
@@ -86,34 +86,17 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
86
86
|
*/
|
|
87
87
|
addVertex(keyOrVertex, value) {
|
|
88
88
|
if (keyOrVertex instanceof AbstractVertex) {
|
|
89
|
-
return this.
|
|
89
|
+
return this._addVertex(keyOrVertex);
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
const newVertex = this.createVertex(keyOrVertex, value);
|
|
93
|
-
return this.
|
|
93
|
+
return this._addVertex(newVertex);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
isVertexKey(potentialKey) {
|
|
97
97
|
const potentialKeyType = typeof potentialKey;
|
|
98
98
|
return potentialKeyType === "string" || potentialKeyType === "number";
|
|
99
99
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
102
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
103
|
-
*/
|
|
104
|
-
/**
|
|
105
|
-
* Time Complexity: O(1) - Constant time for Map operations.
|
|
106
|
-
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
107
|
-
*
|
|
108
|
-
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
109
|
-
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
110
|
-
* (`VertexKey`).
|
|
111
|
-
* @returns The method is returning a boolean value.
|
|
112
|
-
*/
|
|
113
|
-
deleteVertex(vertexOrKey) {
|
|
114
|
-
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
115
|
-
return this._vertexMap.delete(vertexKey);
|
|
116
|
-
}
|
|
117
100
|
/**
|
|
118
101
|
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
119
102
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -160,7 +143,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
160
143
|
*/
|
|
161
144
|
addEdge(srcOrEdge, dest, weight, value) {
|
|
162
145
|
if (srcOrEdge instanceof AbstractEdge) {
|
|
163
|
-
return this.
|
|
146
|
+
return this._addEdge(srcOrEdge);
|
|
164
147
|
}
|
|
165
148
|
else {
|
|
166
149
|
if (dest instanceof AbstractVertex || typeof dest === 'string' || typeof dest === 'number') {
|
|
@@ -171,7 +154,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
171
154
|
if (dest instanceof AbstractVertex)
|
|
172
155
|
dest = dest.key;
|
|
173
156
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
174
|
-
return this.
|
|
157
|
+
return this._addEdge(newEdge);
|
|
175
158
|
}
|
|
176
159
|
else {
|
|
177
160
|
throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
|
|
@@ -1001,13 +984,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
1001
984
|
getLowMap() {
|
|
1002
985
|
return this.tarjan(false, false, false, false).lowMap;
|
|
1003
986
|
}
|
|
1004
|
-
/**
|
|
1005
|
-
* The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
|
|
1006
|
-
* @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
|
|
1007
|
-
*/
|
|
1008
|
-
getCycles() {
|
|
1009
|
-
return this.tarjan(false, false, false, true).cycles;
|
|
1010
|
-
}
|
|
1011
987
|
/**
|
|
1012
988
|
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
1013
989
|
* @returns an array of VO objects, specifically the cut vertexes.
|
|
@@ -1030,6 +1006,44 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
1030
1006
|
getBridges() {
|
|
1031
1007
|
return this.tarjan(false, true, false, false).bridges;
|
|
1032
1008
|
}
|
|
1009
|
+
/**
|
|
1010
|
+
* O(V+E+C)
|
|
1011
|
+
* O(V+C)
|
|
1012
|
+
*/
|
|
1013
|
+
getCycles(isInclude2Cycle = false) {
|
|
1014
|
+
const cycles = [];
|
|
1015
|
+
const visited = new Set();
|
|
1016
|
+
const dfs = (vertex, currentPath, visited) => {
|
|
1017
|
+
if (visited.has(vertex)) {
|
|
1018
|
+
if ((!isInclude2Cycle && currentPath.length > 2 || isInclude2Cycle && currentPath.length >= 2) && currentPath[0] === vertex.key) {
|
|
1019
|
+
cycles.push([...currentPath]);
|
|
1020
|
+
}
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
visited.add(vertex);
|
|
1024
|
+
currentPath.push(vertex.key);
|
|
1025
|
+
for (const neighbor of this.getNeighbors(vertex)) {
|
|
1026
|
+
neighbor && dfs(neighbor, currentPath, visited);
|
|
1027
|
+
}
|
|
1028
|
+
visited.delete(vertex);
|
|
1029
|
+
currentPath.pop();
|
|
1030
|
+
};
|
|
1031
|
+
for (const vertex of this.vertexMap.values()) {
|
|
1032
|
+
dfs(vertex, [], visited);
|
|
1033
|
+
}
|
|
1034
|
+
// Use a set to eliminate duplicate cycles
|
|
1035
|
+
const uniqueCycles = new Map();
|
|
1036
|
+
for (const cycle of cycles) {
|
|
1037
|
+
const sorted = [...cycle].sort().toString();
|
|
1038
|
+
if (uniqueCycles.has(sorted))
|
|
1039
|
+
continue;
|
|
1040
|
+
else {
|
|
1041
|
+
uniqueCycles.set(sorted, cycle);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
// Convert the unique cycles back to an array
|
|
1045
|
+
return [...uniqueCycles].map(cycleString => cycleString[1]);
|
|
1046
|
+
}
|
|
1033
1047
|
/**
|
|
1034
1048
|
* Time Complexity: O(n)
|
|
1035
1049
|
* Space Complexity: O(n)
|
|
@@ -1092,7 +1106,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
1092
1106
|
yield [vertex.key, vertex.value];
|
|
1093
1107
|
}
|
|
1094
1108
|
}
|
|
1095
|
-
|
|
1109
|
+
_addVertex(newVertex) {
|
|
1096
1110
|
if (this.hasVertex(newVertex)) {
|
|
1097
1111
|
return false;
|
|
1098
1112
|
// throw (new Error('Duplicated vertex key is not allowed'));
|
|
@@ -335,11 +335,11 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
335
335
|
* Time Complexity: O(1)
|
|
336
336
|
* Space Complexity: O(1)
|
|
337
337
|
*
|
|
338
|
-
* The function `
|
|
338
|
+
* The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
|
|
339
339
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
340
340
|
* needs to be added to the graph.
|
|
341
341
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
342
342
|
* source or destination vertex does not exist in the graph.
|
|
343
343
|
*/
|
|
344
|
-
protected
|
|
344
|
+
protected _addEdge(edge: EO): boolean;
|
|
345
345
|
}
|
|
@@ -212,6 +212,10 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
212
212
|
vertexKey = this._getVertexKey(vertexOrKey);
|
|
213
213
|
}
|
|
214
214
|
if (vertex) {
|
|
215
|
+
const neighbors = this.getNeighbors(vertex);
|
|
216
|
+
for (const neighbor of neighbors) {
|
|
217
|
+
this._inEdgeMap.delete(neighbor);
|
|
218
|
+
}
|
|
215
219
|
this._outEdgeMap.delete(vertex);
|
|
216
220
|
this._inEdgeMap.delete(vertex);
|
|
217
221
|
}
|
|
@@ -531,13 +535,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
531
535
|
* Time Complexity: O(1)
|
|
532
536
|
* Space Complexity: O(1)
|
|
533
537
|
*
|
|
534
|
-
* The function `
|
|
538
|
+
* The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
|
|
535
539
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
536
540
|
* needs to be added to the graph.
|
|
537
541
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
538
542
|
* source or destination vertex does not exist in the graph.
|
|
539
543
|
*/
|
|
540
|
-
|
|
544
|
+
_addEdge(edge) {
|
|
541
545
|
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
542
546
|
return false;
|
|
543
547
|
}
|
|
@@ -205,5 +205,5 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
205
205
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
206
206
|
* @returns a boolean value.
|
|
207
207
|
*/
|
|
208
|
-
protected
|
|
208
|
+
protected _addEdge(edge: EO): boolean;
|
|
209
209
|
}
|
|
@@ -337,7 +337,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
337
337
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
338
338
|
* @returns a boolean value.
|
|
339
339
|
*/
|
|
340
|
-
|
|
340
|
+
_addEdge(edge) {
|
|
341
341
|
for (const end of edge.vertexMap) {
|
|
342
342
|
const endVertex = this._getVertex(end);
|
|
343
343
|
if (endVertex === undefined)
|
|
@@ -39,6 +39,30 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
39
39
|
* Time Complexity: O(n), where n is the size of the input array.
|
|
40
40
|
* Space Complexity: O(n)
|
|
41
41
|
*/
|
|
42
|
+
/**
|
|
43
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
44
|
+
* Space Complexity: O(1)
|
|
45
|
+
*
|
|
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.
|
|
48
|
+
*/
|
|
49
|
+
get first(): E | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Time Complexity: O(1)
|
|
52
|
+
* Space Complexity: O(1)
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
56
|
+
* Space Complexity: O(1)
|
|
57
|
+
*
|
|
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.
|
|
60
|
+
*/
|
|
61
|
+
get last(): E | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Time Complexity: O(1)
|
|
64
|
+
* Space Complexity: O(1)
|
|
65
|
+
*/
|
|
42
66
|
/**
|
|
43
67
|
* Time Complexity: O(n), where n is the size of the input array.
|
|
44
68
|
* Space Complexity: O(n)
|
|
@@ -75,7 +99,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
75
99
|
*/
|
|
76
100
|
pop(): E | undefined;
|
|
77
101
|
/**
|
|
78
|
-
* Time Complexity: O(
|
|
102
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
79
103
|
* Space Complexity: O(1)
|
|
80
104
|
*/
|
|
81
105
|
/**
|
|
@@ -88,7 +112,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
88
112
|
*/
|
|
89
113
|
shift(): E | undefined;
|
|
90
114
|
/**
|
|
91
|
-
* Time Complexity: O(
|
|
115
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
92
116
|
* Space Complexity: O(1)
|
|
93
117
|
*/
|
|
94
118
|
/**
|
|
@@ -198,10 +222,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
198
222
|
* existing value or node is not found in the doubly linked list.
|
|
199
223
|
*/
|
|
200
224
|
addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
201
|
-
/**
|
|
202
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
203
|
-
* Space Complexity: O(1)
|
|
204
|
-
*/
|
|
205
225
|
/**
|
|
206
226
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
207
227
|
* Space Complexity: O(1)
|
|
@@ -213,10 +233,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
213
233
|
* bounds.
|
|
214
234
|
*/
|
|
215
235
|
deleteAt(index: number): boolean;
|
|
216
|
-
/**
|
|
217
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
218
|
-
* Space Complexity: O(1)
|
|
219
|
-
*/
|
|
220
236
|
/**
|
|
221
237
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
222
238
|
* Space Complexity: O(1)
|
|
@@ -228,11 +244,19 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
228
244
|
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
|
|
229
245
|
*/
|
|
230
246
|
delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
249
|
+
* Space Complexity: O(1)
|
|
250
|
+
*/
|
|
231
251
|
/**
|
|
232
252
|
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
233
253
|
* @returns A boolean value is being returned.
|
|
234
254
|
*/
|
|
235
255
|
isEmpty(): boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
258
|
+
* Space Complexity: O(1)
|
|
259
|
+
*/
|
|
236
260
|
/**
|
|
237
261
|
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
238
262
|
*/
|
|
@@ -269,7 +293,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
269
293
|
indexOf(value: E): number;
|
|
270
294
|
/**
|
|
271
295
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
272
|
-
* Space Complexity: O(
|
|
296
|
+
* Space Complexity: O(n)
|
|
273
297
|
*/
|
|
274
298
|
/**
|
|
275
299
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -285,7 +309,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
285
309
|
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
286
310
|
/**
|
|
287
311
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
288
|
-
* Space Complexity: O(
|
|
312
|
+
* Space Complexity: O(n)
|
|
289
313
|
*/
|
|
290
314
|
/**
|
|
291
315
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -295,7 +319,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
295
319
|
*/
|
|
296
320
|
reverse(): this;
|
|
297
321
|
/**
|
|
298
|
-
* Time Complexity: O(n)
|
|
322
|
+
* Time Complexity: O(n)
|
|
299
323
|
* Space Complexity: O(n)
|
|
300
324
|
*/
|
|
301
325
|
/**
|
|
@@ -319,8 +343,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
319
343
|
*/
|
|
320
344
|
toReversedArray(): E[];
|
|
321
345
|
/**
|
|
322
|
-
* Time Complexity: O(
|
|
323
|
-
* Space Complexity: O(
|
|
346
|
+
* Time Complexity: O(1)
|
|
347
|
+
* Space Complexity: O(1)
|
|
324
348
|
*/
|
|
325
349
|
/**
|
|
326
350
|
* Time Complexity: O(n)
|
|
@@ -341,8 +365,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
341
365
|
*/
|
|
342
366
|
filter(callback: ElementCallback<E, boolean>, thisArg?: any): DoublyLinkedList<E>;
|
|
343
367
|
/**
|
|
344
|
-
* Time Complexity: O(
|
|
345
|
-
* Space Complexity: O(
|
|
368
|
+
* Time Complexity: O(1)
|
|
369
|
+
* Space Complexity: O(1)
|
|
346
370
|
*/
|
|
347
371
|
/**
|
|
348
372
|
* Time Complexity: O(n)
|
|
@@ -388,7 +412,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
388
412
|
*/
|
|
389
413
|
pollLast(): E | undefined;
|
|
390
414
|
/**
|
|
391
|
-
* Time Complexity: O(
|
|
415
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
392
416
|
* Space Complexity: O(1)
|
|
393
417
|
*/
|
|
394
418
|
/**
|
|
@@ -401,7 +425,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
401
425
|
*/
|
|
402
426
|
pollFirst(): E | undefined;
|
|
403
427
|
/**
|
|
404
|
-
* Time Complexity: O(
|
|
428
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
405
429
|
* Space Complexity: O(1)
|
|
406
430
|
*/
|
|
407
431
|
/**
|
|
@@ -413,30 +437,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
413
437
|
* doubly linked list.
|
|
414
438
|
*/
|
|
415
439
|
addFirst(value: E): void;
|
|
416
|
-
/**
|
|
417
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
418
|
-
* Space Complexity: O(1)
|
|
419
|
-
*/
|
|
420
|
-
/**
|
|
421
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
422
|
-
* Space Complexity: O(1)
|
|
423
|
-
*
|
|
424
|
-
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
425
|
-
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
426
|
-
*/
|
|
427
|
-
get first(): E | undefined;
|
|
428
|
-
/**
|
|
429
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
430
|
-
* Space Complexity: O(1)
|
|
431
|
-
*/
|
|
432
|
-
/**
|
|
433
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
434
|
-
* Space Complexity: O(1)
|
|
435
|
-
*
|
|
436
|
-
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
437
|
-
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
438
|
-
*/
|
|
439
|
-
get last(): E | undefined;
|
|
440
440
|
/**
|
|
441
441
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
442
442
|
*/
|
|
@@ -49,6 +49,36 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
49
49
|
* Time Complexity: O(n), where n is the size of the input array.
|
|
50
50
|
* Space Complexity: O(n)
|
|
51
51
|
*/
|
|
52
|
+
/**
|
|
53
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
54
|
+
* Space Complexity: O(1)
|
|
55
|
+
*
|
|
56
|
+
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
57
|
+
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
58
|
+
*/
|
|
59
|
+
get first() {
|
|
60
|
+
var _a;
|
|
61
|
+
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Time Complexity: O(1)
|
|
65
|
+
* Space Complexity: O(1)
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
69
|
+
* Space Complexity: O(1)
|
|
70
|
+
*
|
|
71
|
+
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
72
|
+
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
73
|
+
*/
|
|
74
|
+
get last() {
|
|
75
|
+
var _a;
|
|
76
|
+
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Time Complexity: O(1)
|
|
80
|
+
* Space Complexity: O(1)
|
|
81
|
+
*/
|
|
52
82
|
/**
|
|
53
83
|
* Time Complexity: O(n), where n is the size of the input array.
|
|
54
84
|
* Space Complexity: O(n)
|
|
@@ -118,7 +148,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
118
148
|
return removedNode.value;
|
|
119
149
|
}
|
|
120
150
|
/**
|
|
121
|
-
* Time Complexity: O(
|
|
151
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
122
152
|
* Space Complexity: O(1)
|
|
123
153
|
*/
|
|
124
154
|
/**
|
|
@@ -145,7 +175,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
145
175
|
return removedNode.value;
|
|
146
176
|
}
|
|
147
177
|
/**
|
|
148
|
-
* Time Complexity: O(
|
|
178
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
149
179
|
* Space Complexity: O(1)
|
|
150
180
|
*/
|
|
151
181
|
/**
|
|
@@ -359,10 +389,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
359
389
|
}
|
|
360
390
|
return false;
|
|
361
391
|
}
|
|
362
|
-
/**
|
|
363
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
364
|
-
* Space Complexity: O(1)
|
|
365
|
-
*/
|
|
366
392
|
/**
|
|
367
393
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
368
394
|
* Space Complexity: O(1)
|
|
@@ -392,10 +418,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
392
418
|
this._size--;
|
|
393
419
|
return true;
|
|
394
420
|
}
|
|
395
|
-
/**
|
|
396
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
397
|
-
* Space Complexity: O(1)
|
|
398
|
-
*/
|
|
399
421
|
/**
|
|
400
422
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
401
423
|
* Space Complexity: O(1)
|
|
@@ -432,6 +454,10 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
432
454
|
}
|
|
433
455
|
return false;
|
|
434
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
459
|
+
* Space Complexity: O(1)
|
|
460
|
+
*/
|
|
435
461
|
/**
|
|
436
462
|
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
437
463
|
* @returns A boolean value is being returned.
|
|
@@ -439,6 +465,10 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
439
465
|
isEmpty() {
|
|
440
466
|
return this.size === 0;
|
|
441
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
470
|
+
* Space Complexity: O(1)
|
|
471
|
+
*/
|
|
442
472
|
/**
|
|
443
473
|
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
444
474
|
*/
|
|
@@ -499,7 +529,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
499
529
|
}
|
|
500
530
|
/**
|
|
501
531
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
502
|
-
* Space Complexity: O(
|
|
532
|
+
* Space Complexity: O(n)
|
|
503
533
|
*/
|
|
504
534
|
/**
|
|
505
535
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -524,7 +554,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
524
554
|
}
|
|
525
555
|
/**
|
|
526
556
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
527
|
-
* Space Complexity: O(
|
|
557
|
+
* Space Complexity: O(n)
|
|
528
558
|
*/
|
|
529
559
|
/**
|
|
530
560
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -543,7 +573,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
543
573
|
return this;
|
|
544
574
|
}
|
|
545
575
|
/**
|
|
546
|
-
* Time Complexity: O(n)
|
|
576
|
+
* Time Complexity: O(n)
|
|
547
577
|
* Space Complexity: O(n)
|
|
548
578
|
*/
|
|
549
579
|
/**
|
|
@@ -583,8 +613,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
583
613
|
return array;
|
|
584
614
|
}
|
|
585
615
|
/**
|
|
586
|
-
* Time Complexity: O(
|
|
587
|
-
* Space Complexity: O(
|
|
616
|
+
* Time Complexity: O(1)
|
|
617
|
+
* Space Complexity: O(1)
|
|
588
618
|
*/
|
|
589
619
|
/**
|
|
590
620
|
* Time Complexity: O(n)
|
|
@@ -615,8 +645,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
615
645
|
return filteredList;
|
|
616
646
|
}
|
|
617
647
|
/**
|
|
618
|
-
* Time Complexity: O(
|
|
619
|
-
* Space Complexity: O(
|
|
648
|
+
* Time Complexity: O(1)
|
|
649
|
+
* Space Complexity: O(1)
|
|
620
650
|
*/
|
|
621
651
|
/**
|
|
622
652
|
* Time Complexity: O(n)
|
|
@@ -674,7 +704,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
674
704
|
return this.pop();
|
|
675
705
|
}
|
|
676
706
|
/**
|
|
677
|
-
* Time Complexity: O(
|
|
707
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
678
708
|
* Space Complexity: O(1)
|
|
679
709
|
*/
|
|
680
710
|
/**
|
|
@@ -689,7 +719,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
689
719
|
return this.shift();
|
|
690
720
|
}
|
|
691
721
|
/**
|
|
692
|
-
* Time Complexity: O(
|
|
722
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
693
723
|
* Space Complexity: O(1)
|
|
694
724
|
*/
|
|
695
725
|
/**
|
|
@@ -703,36 +733,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
703
733
|
addFirst(value) {
|
|
704
734
|
this.unshift(value);
|
|
705
735
|
}
|
|
706
|
-
/**
|
|
707
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
708
|
-
* Space Complexity: O(1)
|
|
709
|
-
*/
|
|
710
|
-
/**
|
|
711
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
712
|
-
* Space Complexity: O(1)
|
|
713
|
-
*
|
|
714
|
-
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
715
|
-
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
716
|
-
*/
|
|
717
|
-
get first() {
|
|
718
|
-
var _a;
|
|
719
|
-
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
723
|
-
* Space Complexity: O(1)
|
|
724
|
-
*/
|
|
725
|
-
/**
|
|
726
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
727
|
-
* Space Complexity: O(1)
|
|
728
|
-
*
|
|
729
|
-
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
730
|
-
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
731
|
-
*/
|
|
732
|
-
get last() {
|
|
733
|
-
var _a;
|
|
734
|
-
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
|
|
735
|
-
}
|
|
736
736
|
/**
|
|
737
737
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
738
738
|
*/
|