data-structure-typed 1.49.2 → 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/CHANGELOG.md +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +7 -7
- package/dist/cjs/data-structures/graph/abstract-graph.js +43 -12
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +49 -49
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/cjs/data-structures/queue/queue.js +40 -40
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.js +43 -12
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +47 -47
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/mjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/mjs/data-structures/queue/queue.js +39 -39
- package/dist/umd/data-structure-typed.js +171 -140
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- 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/linked-list/doubly-linked-list.ts +53 -53
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/queue.ts +45 -45
- package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +48 -3
- package/test/unit/data-structures/graph/undirected-graph.test.ts +48 -4
- package/test/unit/data-structures/heap/heap.test.ts +6 -1
|
@@ -37,6 +37,36 @@ class Queue extends base_1.IterableElementBase {
|
|
|
37
37
|
get size() {
|
|
38
38
|
return this.nodes.length - this.offset;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
42
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
43
|
+
*
|
|
44
|
+
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
45
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
46
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
47
|
+
*/
|
|
48
|
+
get first() {
|
|
49
|
+
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Time Complexity: O(1) - constant time as it adds an element to the end of the array.
|
|
53
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
57
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
58
|
+
*
|
|
59
|
+
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
60
|
+
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
61
|
+
* array is empty, it returns `undefined`.
|
|
62
|
+
*/
|
|
63
|
+
get last() {
|
|
64
|
+
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
|
|
68
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
69
|
+
*/
|
|
40
70
|
/**
|
|
41
71
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
42
72
|
* @public
|
|
@@ -49,7 +79,7 @@ class Queue extends base_1.IterableElementBase {
|
|
|
49
79
|
return new Queue(elements);
|
|
50
80
|
}
|
|
51
81
|
/**
|
|
52
|
-
* Time Complexity: O(1) - constant time as it
|
|
82
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
53
83
|
* Space Complexity: O(1) - no additional space is used.
|
|
54
84
|
*/
|
|
55
85
|
/**
|
|
@@ -65,7 +95,7 @@ class Queue extends base_1.IterableElementBase {
|
|
|
65
95
|
return true;
|
|
66
96
|
}
|
|
67
97
|
/**
|
|
68
|
-
* Time Complexity: O(
|
|
98
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
69
99
|
* Space Complexity: O(1) - no additional space is used.
|
|
70
100
|
*/
|
|
71
101
|
/**
|
|
@@ -89,21 +119,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
89
119
|
this._offset = 0;
|
|
90
120
|
return first;
|
|
91
121
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
94
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
98
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
99
|
-
*
|
|
100
|
-
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
101
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
102
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
103
|
-
*/
|
|
104
|
-
get first() {
|
|
105
|
-
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
106
|
-
}
|
|
107
122
|
/**
|
|
108
123
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
109
124
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -119,21 +134,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
119
134
|
peek() {
|
|
120
135
|
return this.first;
|
|
121
136
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
124
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
125
|
-
*/
|
|
126
|
-
/**
|
|
127
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
128
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
129
|
-
*
|
|
130
|
-
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
131
|
-
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
132
|
-
* array is empty, it returns `undefined`.
|
|
133
|
-
*/
|
|
134
|
-
get last() {
|
|
135
|
-
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
136
|
-
}
|
|
137
137
|
/**
|
|
138
138
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
139
139
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -315,6 +315,14 @@ exports.Queue = Queue;
|
|
|
315
315
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
316
316
|
*/
|
|
317
317
|
class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
318
|
+
/**
|
|
319
|
+
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
320
|
+
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
321
|
+
*/
|
|
322
|
+
get first() {
|
|
323
|
+
var _a;
|
|
324
|
+
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
325
|
+
}
|
|
318
326
|
/**
|
|
319
327
|
* The enqueue function adds a value to the end of an array.
|
|
320
328
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -329,14 +337,6 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
|
329
337
|
dequeue() {
|
|
330
338
|
return this.shift();
|
|
331
339
|
}
|
|
332
|
-
/**
|
|
333
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
334
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
335
|
-
*/
|
|
336
|
-
get first() {
|
|
337
|
-
var _a;
|
|
338
|
-
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
339
|
-
}
|
|
340
340
|
/**
|
|
341
341
|
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
342
342
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAMA,kCAA8C;AAC9C,gDAAkD;AAElD;;;;;;;;GAQG;AACH,MAAa,KAAe,SAAQ,0BAAsB;IACxD;;;;;OAKG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IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC;QACb,CAAC;IACH,CAAC;CACF;AA7UD,sBA6UC;AAED;;;;;GAKG;AACH,MAAa,eAAyB,SAAQ,8BAAmB;IAC/D;;;OAGG;IACH,IAAI,KAAK;;QACP,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KAAQ;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAhCD,0CAgCC"}
|
|
@@ -432,11 +432,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
432
432
|
* type `number`.
|
|
433
433
|
*/
|
|
434
434
|
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
435
|
/**
|
|
441
436
|
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
442
437
|
* @returns an array of VO objects, specifically the cut vertexes.
|
|
@@ -453,6 +448,11 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
453
448
|
* @returns the bridges found using the Tarjan algorithm.
|
|
454
449
|
*/
|
|
455
450
|
getBridges(): EO[];
|
|
451
|
+
/**
|
|
452
|
+
* O(V+E+C)
|
|
453
|
+
* O(V+C)
|
|
454
|
+
*/
|
|
455
|
+
getCycles(isInclude2Cycle?: boolean): VertexKey[][];
|
|
456
456
|
/**
|
|
457
457
|
* Time Complexity: O(n)
|
|
458
458
|
* Space Complexity: O(n)
|
|
@@ -493,8 +493,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
493
493
|
*/
|
|
494
494
|
map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
|
|
495
495
|
protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
|
|
496
|
-
protected abstract
|
|
497
|
-
protected
|
|
496
|
+
protected abstract _addEdge(edge: EO): boolean;
|
|
497
|
+
protected _addVertex(newVertex: VO): boolean;
|
|
498
498
|
protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
|
|
499
499
|
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
|
|
500
500
|
}
|
|
@@ -86,11 +86,11 @@ export class AbstractGraph extends 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) {
|
|
@@ -160,7 +160,7 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
160
160
|
*/
|
|
161
161
|
addEdge(srcOrEdge, dest, weight, value) {
|
|
162
162
|
if (srcOrEdge instanceof AbstractEdge) {
|
|
163
|
-
return this.
|
|
163
|
+
return this._addEdge(srcOrEdge);
|
|
164
164
|
}
|
|
165
165
|
else {
|
|
166
166
|
if (dest instanceof AbstractVertex || typeof dest === 'string' || typeof dest === 'number') {
|
|
@@ -171,7 +171,7 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
171
171
|
if (dest instanceof AbstractVertex)
|
|
172
172
|
dest = dest.key;
|
|
173
173
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
174
|
-
return this.
|
|
174
|
+
return this._addEdge(newEdge);
|
|
175
175
|
}
|
|
176
176
|
else {
|
|
177
177
|
throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
|
|
@@ -996,13 +996,6 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
996
996
|
getLowMap() {
|
|
997
997
|
return this.tarjan(false, false, false, false).lowMap;
|
|
998
998
|
}
|
|
999
|
-
/**
|
|
1000
|
-
* The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
|
|
1001
|
-
* @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
|
|
1002
|
-
*/
|
|
1003
|
-
getCycles() {
|
|
1004
|
-
return this.tarjan(false, false, false, true).cycles;
|
|
1005
|
-
}
|
|
1006
999
|
/**
|
|
1007
1000
|
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
1008
1001
|
* @returns an array of VO objects, specifically the cut vertexes.
|
|
@@ -1025,6 +1018,44 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
1025
1018
|
getBridges() {
|
|
1026
1019
|
return this.tarjan(false, true, false, false).bridges;
|
|
1027
1020
|
}
|
|
1021
|
+
/**
|
|
1022
|
+
* O(V+E+C)
|
|
1023
|
+
* O(V+C)
|
|
1024
|
+
*/
|
|
1025
|
+
getCycles(isInclude2Cycle = false) {
|
|
1026
|
+
const cycles = [];
|
|
1027
|
+
const visited = new Set();
|
|
1028
|
+
const dfs = (vertex, currentPath, visited) => {
|
|
1029
|
+
if (visited.has(vertex)) {
|
|
1030
|
+
if ((!isInclude2Cycle && currentPath.length > 2 || isInclude2Cycle && currentPath.length >= 2) && currentPath[0] === vertex.key) {
|
|
1031
|
+
cycles.push([...currentPath]);
|
|
1032
|
+
}
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
visited.add(vertex);
|
|
1036
|
+
currentPath.push(vertex.key);
|
|
1037
|
+
for (const neighbor of this.getNeighbors(vertex)) {
|
|
1038
|
+
neighbor && dfs(neighbor, currentPath, visited);
|
|
1039
|
+
}
|
|
1040
|
+
visited.delete(vertex);
|
|
1041
|
+
currentPath.pop();
|
|
1042
|
+
};
|
|
1043
|
+
for (const vertex of this.vertexMap.values()) {
|
|
1044
|
+
dfs(vertex, [], visited);
|
|
1045
|
+
}
|
|
1046
|
+
// Use a set to eliminate duplicate cycles
|
|
1047
|
+
const uniqueCycles = new Map();
|
|
1048
|
+
for (const cycle of cycles) {
|
|
1049
|
+
const sorted = [...cycle].sort().toString();
|
|
1050
|
+
if (uniqueCycles.has(sorted))
|
|
1051
|
+
continue;
|
|
1052
|
+
else {
|
|
1053
|
+
uniqueCycles.set(sorted, cycle);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
// Convert the unique cycles back to an array
|
|
1057
|
+
return [...uniqueCycles].map(cycleString => cycleString[1]);
|
|
1058
|
+
}
|
|
1028
1059
|
/**
|
|
1029
1060
|
* Time Complexity: O(n)
|
|
1030
1061
|
* Space Complexity: O(n)
|
|
@@ -1087,7 +1118,7 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
1087
1118
|
yield [vertex.key, vertex.value];
|
|
1088
1119
|
}
|
|
1089
1120
|
}
|
|
1090
|
-
|
|
1121
|
+
_addVertex(newVertex) {
|
|
1091
1122
|
if (this.hasVertex(newVertex)) {
|
|
1092
1123
|
return false;
|
|
1093
1124
|
// 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
|
}
|
|
@@ -528,13 +528,13 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
528
528
|
* Time Complexity: O(1)
|
|
529
529
|
* Space Complexity: O(1)
|
|
530
530
|
*
|
|
531
|
-
* The function `
|
|
531
|
+
* The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
|
|
532
532
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
533
533
|
* needs to be added to the graph.
|
|
534
534
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
535
535
|
* source or destination vertex does not exist in the graph.
|
|
536
536
|
*/
|
|
537
|
-
|
|
537
|
+
_addEdge(edge) {
|
|
538
538
|
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
539
539
|
return false;
|
|
540
540
|
}
|
|
@@ -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
|
}
|
|
@@ -332,7 +332,7 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
332
332
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
333
333
|
* @returns a boolean value.
|
|
334
334
|
*/
|
|
335
|
-
|
|
335
|
+
_addEdge(edge) {
|
|
336
336
|
for (const end of edge.vertexMap) {
|
|
337
337
|
const endVertex = this._getVertex(end);
|
|
338
338
|
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
|
*/
|