data-structure-typed 1.47.7 → 1.47.8
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/README.md +98 -17
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +161 -161
- 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/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/graph/abstract-graph.ts +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/test/integration/index.html +102 -33
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +10 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
|
@@ -61,14 +61,14 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
61
61
|
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
62
62
|
* Space Complexity: O(1)
|
|
63
63
|
*
|
|
64
|
-
* The function `getEdge` returns the first edge that connects two vertices, or
|
|
65
|
-
* @param {VO | VertexKey |
|
|
66
|
-
* object), `
|
|
67
|
-
* @param {VO | VertexKey |
|
|
68
|
-
* object), `
|
|
69
|
-
* @returns an edge (EO) or
|
|
64
|
+
* The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
|
|
65
|
+
* @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
66
|
+
* object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
67
|
+
* @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
68
|
+
* object), `undefined`, or `VertexKey` (vertex ID).
|
|
69
|
+
* @returns an edge (EO) or undefined.
|
|
70
70
|
*/
|
|
71
|
-
getEdge(v1: VO | VertexKey |
|
|
71
|
+
getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
|
|
72
72
|
/**
|
|
73
73
|
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
74
74
|
* Space Complexity: O(1)
|
|
@@ -81,9 +81,9 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
81
81
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
82
82
|
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
83
83
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
84
|
-
* @returns the removed edge (EO) if it exists, or
|
|
84
|
+
* @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
|
|
85
85
|
*/
|
|
86
|
-
deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO |
|
|
86
|
+
deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined;
|
|
87
87
|
/**
|
|
88
88
|
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
89
89
|
* Space Complexity: O(1)
|
|
@@ -94,9 +94,9 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
94
94
|
*
|
|
95
95
|
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
96
96
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
97
|
-
* @returns The method is returning either the removed edge (of type EO) or
|
|
97
|
+
* @returns The method is returning either the removed edge (of type EO) or undefined if the edge was not found.
|
|
98
98
|
*/
|
|
99
|
-
deleteEdge(edge: EO): EO |
|
|
99
|
+
deleteEdge(edge: EO): EO | undefined;
|
|
100
100
|
/**
|
|
101
101
|
* Time Complexity: O(1)
|
|
102
102
|
* Space Complexity: O(1)
|
|
@@ -161,12 +161,12 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
161
161
|
* Space Complexity: O(1)
|
|
162
162
|
*
|
|
163
163
|
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
164
|
-
* it returns
|
|
164
|
+
* it returns undefined.
|
|
165
165
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
166
166
|
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
167
|
-
* graph. If the edge does not exist, it returns `
|
|
167
|
+
* graph. If the edge does not exist, it returns `undefined`.
|
|
168
168
|
*/
|
|
169
|
-
getEndsOfEdge(edge: EO): [VO, VO] |
|
|
169
|
+
getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
170
170
|
/**
|
|
171
171
|
* Time Complexity: O(1)
|
|
172
172
|
* Space Complexity: O(1)
|
|
@@ -81,23 +81,23 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
81
81
|
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
82
82
|
* Space Complexity: O(1)
|
|
83
83
|
*
|
|
84
|
-
* The function `getEdge` returns the first edge that connects two vertices, or
|
|
85
|
-
* @param {VO | VertexKey |
|
|
86
|
-
* object), `
|
|
87
|
-
* @param {VO | VertexKey |
|
|
88
|
-
* object), `
|
|
89
|
-
* @returns an edge (EO) or
|
|
84
|
+
* The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
|
|
85
|
+
* @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
86
|
+
* object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
87
|
+
* @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
88
|
+
* object), `undefined`, or `VertexKey` (vertex ID).
|
|
89
|
+
* @returns an edge (EO) or undefined.
|
|
90
90
|
*/
|
|
91
91
|
getEdge(v1, v2) {
|
|
92
92
|
let edges = [];
|
|
93
|
-
if (v1 !==
|
|
93
|
+
if (v1 !== undefined && v2 !== undefined) {
|
|
94
94
|
const vertex1 = this._getVertex(v1);
|
|
95
95
|
const vertex2 = this._getVertex(v2);
|
|
96
96
|
if (vertex1 && vertex2) {
|
|
97
97
|
edges = this._edges.get(vertex1)?.filter(e => e.vertices.includes(vertex2.key));
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
return edges ? edges[0] ||
|
|
100
|
+
return edges ? edges[0] || undefined : undefined;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
@@ -111,18 +111,18 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
111
111
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
112
112
|
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
113
113
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
114
|
-
* @returns the removed edge (EO) if it exists, or
|
|
114
|
+
* @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
|
|
115
115
|
*/
|
|
116
116
|
deleteEdgeBetween(v1, v2) {
|
|
117
117
|
const vertex1 = this._getVertex(v1);
|
|
118
118
|
const vertex2 = this._getVertex(v2);
|
|
119
119
|
if (!vertex1 || !vertex2) {
|
|
120
|
-
return
|
|
120
|
+
return undefined;
|
|
121
121
|
}
|
|
122
122
|
const v1Edges = this._edges.get(vertex1);
|
|
123
|
-
let removed =
|
|
123
|
+
let removed = undefined;
|
|
124
124
|
if (v1Edges) {
|
|
125
|
-
removed = arrayRemove(v1Edges, (e) => e.vertices.includes(vertex2.key))[0] ||
|
|
125
|
+
removed = arrayRemove(v1Edges, (e) => e.vertices.includes(vertex2.key))[0] || undefined;
|
|
126
126
|
}
|
|
127
127
|
const v2Edges = this._edges.get(vertex2);
|
|
128
128
|
if (v2Edges) {
|
|
@@ -140,7 +140,7 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
140
140
|
*
|
|
141
141
|
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
142
142
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
143
|
-
* @returns The method is returning either the removed edge (of type EO) or
|
|
143
|
+
* @returns The method is returning either the removed edge (of type EO) or undefined if the edge was not found.
|
|
144
144
|
*/
|
|
145
145
|
deleteEdge(edge) {
|
|
146
146
|
return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
@@ -246,14 +246,14 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
246
246
|
* Space Complexity: O(1)
|
|
247
247
|
*
|
|
248
248
|
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
249
|
-
* it returns
|
|
249
|
+
* it returns undefined.
|
|
250
250
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
251
251
|
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
252
|
-
* graph. If the edge does not exist, it returns `
|
|
252
|
+
* graph. If the edge does not exist, it returns `undefined`.
|
|
253
253
|
*/
|
|
254
254
|
getEndsOfEdge(edge) {
|
|
255
255
|
if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
|
|
256
|
-
return
|
|
256
|
+
return undefined;
|
|
257
257
|
}
|
|
258
258
|
const v1 = this._getVertex(edge.vertices[0]);
|
|
259
259
|
const v2 = this._getVertex(edge.vertices[1]);
|
|
@@ -261,7 +261,7 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
261
261
|
return [v1, v2];
|
|
262
262
|
}
|
|
263
263
|
else {
|
|
264
|
-
return
|
|
264
|
+
return undefined;
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
/**
|
|
@@ -279,7 +279,7 @@ export class UndirectedGraph extends AbstractGraph {
|
|
|
279
279
|
_addEdgeOnly(edge) {
|
|
280
280
|
for (const end of edge.vertices) {
|
|
281
281
|
const endVertex = this._getVertex(end);
|
|
282
|
-
if (endVertex ===
|
|
282
|
+
if (endVertex === undefined)
|
|
283
283
|
return false;
|
|
284
284
|
if (endVertex) {
|
|
285
285
|
const edges = this._edges.get(endVertex);
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class DoublyLinkedListNode<E = any> {
|
|
9
9
|
value: E;
|
|
10
|
-
next: DoublyLinkedListNode<E> |
|
|
11
|
-
prev: DoublyLinkedListNode<E> |
|
|
10
|
+
next: DoublyLinkedListNode<E> | undefined;
|
|
11
|
+
prev: DoublyLinkedListNode<E> | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
14
14
|
* @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
|
|
@@ -21,10 +21,10 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
21
21
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
22
22
|
*/
|
|
23
23
|
constructor(elements?: Iterable<E>);
|
|
24
|
-
protected _head: DoublyLinkedListNode<E> |
|
|
25
|
-
get head(): DoublyLinkedListNode<E> |
|
|
26
|
-
protected _tail: DoublyLinkedListNode<E> |
|
|
27
|
-
get tail(): DoublyLinkedListNode<E> |
|
|
24
|
+
protected _head: DoublyLinkedListNode<E> | undefined;
|
|
25
|
+
get head(): DoublyLinkedListNode<E> | undefined;
|
|
26
|
+
protected _tail: DoublyLinkedListNode<E> | undefined;
|
|
27
|
+
get tail(): DoublyLinkedListNode<E> | undefined;
|
|
28
28
|
protected _length: number;
|
|
29
29
|
get length(): number;
|
|
30
30
|
get size(): number;
|
|
@@ -76,7 +76,7 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
76
76
|
*
|
|
77
77
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
78
78
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
79
|
-
* list is empty, it returns
|
|
79
|
+
* list is empty, it returns undefined.
|
|
80
80
|
*/
|
|
81
81
|
pop(): E | undefined;
|
|
82
82
|
/**
|
|
@@ -89,7 +89,7 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
89
89
|
*
|
|
90
90
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
91
91
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
92
|
-
* list is empty, it returns
|
|
92
|
+
* list is empty, it returns undefined.
|
|
93
93
|
*/
|
|
94
94
|
popLast(): E | undefined;
|
|
95
95
|
/**
|
|
@@ -152,8 +152,8 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
152
152
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
153
153
|
* Space Complexity: O(1)
|
|
154
154
|
*
|
|
155
|
-
* The `getFirst` function returns the first node in a doubly linked list, or
|
|
156
|
-
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `
|
|
155
|
+
* The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
156
|
+
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
157
157
|
*/
|
|
158
158
|
getFirst(): E | undefined;
|
|
159
159
|
/**
|
|
@@ -164,8 +164,8 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
164
164
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
165
165
|
* Space Complexity: O(1)
|
|
166
166
|
*
|
|
167
|
-
* The `getLast` function returns the last node in a doubly linked list, or
|
|
168
|
-
* @returns The method `getLast()` returns the last node of the doubly linked list, or `
|
|
167
|
+
* The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
168
|
+
* @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
169
169
|
*/
|
|
170
170
|
getLast(): E | undefined;
|
|
171
171
|
/**
|
|
@@ -176,11 +176,11 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
176
176
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
177
177
|
* Space Complexity: O(1)
|
|
178
178
|
*
|
|
179
|
-
* The `getAt` function returns the value at a specified index in a linked list, or
|
|
179
|
+
* The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
180
180
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
181
181
|
* retrieve from the list.
|
|
182
182
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
183
|
-
* or the linked list is empty, it will return
|
|
183
|
+
* or the linked list is empty, it will return undefined.
|
|
184
184
|
*/
|
|
185
185
|
getAt(index: number): E | undefined;
|
|
186
186
|
/**
|
|
@@ -191,14 +191,14 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
191
191
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
192
192
|
* Space Complexity: O(1)
|
|
193
193
|
*
|
|
194
|
-
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or
|
|
194
|
+
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
195
195
|
* range.
|
|
196
196
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
197
197
|
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
198
198
|
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
199
|
-
* valid range of the linked list, otherwise it returns `
|
|
199
|
+
* valid range of the linked list, otherwise it returns `undefined`.
|
|
200
200
|
*/
|
|
201
|
-
getNodeAt(index: number): DoublyLinkedListNode<E> |
|
|
201
|
+
getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
|
|
202
202
|
/**
|
|
203
203
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
204
204
|
* Space Complexity: O(1)
|
|
@@ -208,12 +208,12 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
208
208
|
* Space Complexity: O(1)
|
|
209
209
|
*
|
|
210
210
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
211
|
-
* node if found, otherwise it returns
|
|
211
|
+
* node if found, otherwise it returns undefined.
|
|
212
212
|
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
213
213
|
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
|
|
214
|
-
* is found in the linked list. If no such node is found, it returns `
|
|
214
|
+
* is found in the linked list. If no such node is found, it returns `undefined`.
|
|
215
215
|
*/
|
|
216
|
-
getNode(value: E |
|
|
216
|
+
getNode(value: E | undefined): DoublyLinkedListNode<E> | undefined;
|
|
217
217
|
/**
|
|
218
218
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
219
219
|
* Space Complexity: O(1)
|
|
@@ -277,7 +277,7 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
277
277
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
278
278
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
279
279
|
* data structure. It is of type number.
|
|
280
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `
|
|
280
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
281
281
|
* bounds.
|
|
282
282
|
*/
|
|
283
283
|
deleteAt(index: number): E | undefined;
|
|
@@ -295,14 +295,14 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
295
295
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
|
|
296
296
|
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
|
|
297
297
|
*/
|
|
298
|
-
delete(valOrNode: E | DoublyLinkedListNode<E> |
|
|
298
|
+
delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
299
299
|
/**
|
|
300
300
|
* The function checks if a variable has a length greater than zero and returns a boolean value.
|
|
301
301
|
* @returns A boolean value is being returned.
|
|
302
302
|
*/
|
|
303
303
|
isEmpty(): boolean;
|
|
304
304
|
/**
|
|
305
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to
|
|
305
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
306
306
|
*/
|
|
307
307
|
clear(): void;
|
|
308
308
|
/**
|
|
@@ -317,9 +317,9 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
317
317
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
318
318
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
319
319
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
320
|
-
* the callback function. If no element satisfies the condition, it returns `
|
|
320
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
321
321
|
*/
|
|
322
|
-
find(callback: (value: E) => boolean): E |
|
|
322
|
+
find(callback: (value: E) => boolean): E | undefined;
|
|
323
323
|
/**
|
|
324
324
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
325
325
|
* Space Complexity: O(1)
|
|
@@ -344,13 +344,13 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
344
344
|
* Space Complexity: O(1)
|
|
345
345
|
*
|
|
346
346
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
347
|
-
* value that satisfies the given callback function, or
|
|
347
|
+
* value that satisfies the given callback function, or undefined if no value satisfies the callback.
|
|
348
348
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
349
349
|
* function is used to determine whether a given value satisfies a certain condition.
|
|
350
350
|
* @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
|
|
351
|
-
* the callback function. If no value satisfies the condition, it returns `
|
|
351
|
+
* the callback function. If no value satisfies the condition, it returns `undefined`.
|
|
352
352
|
*/
|
|
353
|
-
findBackward(callback: (value: E) => boolean): E |
|
|
353
|
+
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
354
354
|
/**
|
|
355
355
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
356
356
|
* Space Complexity: O(1)
|
|
@@ -16,8 +16,8 @@ export class DoublyLinkedListNode {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(value) {
|
|
18
18
|
this.value = value;
|
|
19
|
-
this.next =
|
|
20
|
-
this.prev =
|
|
19
|
+
this.next = undefined;
|
|
20
|
+
this.prev = undefined;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
export class DoublyLinkedList {
|
|
@@ -25,8 +25,8 @@ export class DoublyLinkedList {
|
|
|
25
25
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
26
26
|
*/
|
|
27
27
|
constructor(elements) {
|
|
28
|
-
this._head =
|
|
29
|
-
this._tail =
|
|
28
|
+
this._head = undefined;
|
|
29
|
+
this._tail = undefined;
|
|
30
30
|
this._length = 0;
|
|
31
31
|
if (elements) {
|
|
32
32
|
for (const el of elements) {
|
|
@@ -117,19 +117,19 @@ export class DoublyLinkedList {
|
|
|
117
117
|
*
|
|
118
118
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
119
119
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
120
|
-
* list is empty, it returns
|
|
120
|
+
* list is empty, it returns undefined.
|
|
121
121
|
*/
|
|
122
122
|
pop() {
|
|
123
123
|
if (!this.tail)
|
|
124
124
|
return undefined;
|
|
125
125
|
const removedNode = this.tail;
|
|
126
126
|
if (this.head === this.tail) {
|
|
127
|
-
this._head =
|
|
128
|
-
this._tail =
|
|
127
|
+
this._head = undefined;
|
|
128
|
+
this._tail = undefined;
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
131
|
this._tail = removedNode.prev;
|
|
132
|
-
this.tail.next =
|
|
132
|
+
this.tail.next = undefined;
|
|
133
133
|
}
|
|
134
134
|
this._length--;
|
|
135
135
|
return removedNode.value;
|
|
@@ -144,7 +144,7 @@ export class DoublyLinkedList {
|
|
|
144
144
|
*
|
|
145
145
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
146
146
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
147
|
-
* list is empty, it returns
|
|
147
|
+
* list is empty, it returns undefined.
|
|
148
148
|
*/
|
|
149
149
|
popLast() {
|
|
150
150
|
return this.pop();
|
|
@@ -166,12 +166,12 @@ export class DoublyLinkedList {
|
|
|
166
166
|
return undefined;
|
|
167
167
|
const removedNode = this.head;
|
|
168
168
|
if (this.head === this.tail) {
|
|
169
|
-
this._head =
|
|
170
|
-
this._tail =
|
|
169
|
+
this._head = undefined;
|
|
170
|
+
this._tail = undefined;
|
|
171
171
|
}
|
|
172
172
|
else {
|
|
173
173
|
this._head = removedNode.next;
|
|
174
|
-
this.head.prev =
|
|
174
|
+
this.head.prev = undefined;
|
|
175
175
|
}
|
|
176
176
|
this._length--;
|
|
177
177
|
return removedNode.value;
|
|
@@ -239,8 +239,8 @@ export class DoublyLinkedList {
|
|
|
239
239
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
240
240
|
* Space Complexity: O(1)
|
|
241
241
|
*
|
|
242
|
-
* The `getFirst` function returns the first node in a doubly linked list, or
|
|
243
|
-
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `
|
|
242
|
+
* The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
243
|
+
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
244
244
|
*/
|
|
245
245
|
getFirst() {
|
|
246
246
|
return this.head?.value;
|
|
@@ -253,8 +253,8 @@ export class DoublyLinkedList {
|
|
|
253
253
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
254
254
|
* Space Complexity: O(1)
|
|
255
255
|
*
|
|
256
|
-
* The `getLast` function returns the last node in a doubly linked list, or
|
|
257
|
-
* @returns The method `getLast()` returns the last node of the doubly linked list, or `
|
|
256
|
+
* The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
257
|
+
* @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
258
258
|
*/
|
|
259
259
|
getLast() {
|
|
260
260
|
return this.tail?.value;
|
|
@@ -267,11 +267,11 @@ export class DoublyLinkedList {
|
|
|
267
267
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
268
268
|
* Space Complexity: O(1)
|
|
269
269
|
*
|
|
270
|
-
* The `getAt` function returns the value at a specified index in a linked list, or
|
|
270
|
+
* The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
271
271
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
272
272
|
* retrieve from the list.
|
|
273
273
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
274
|
-
* or the linked list is empty, it will return
|
|
274
|
+
* or the linked list is empty, it will return undefined.
|
|
275
275
|
*/
|
|
276
276
|
getAt(index) {
|
|
277
277
|
if (index < 0 || index >= this.length)
|
|
@@ -290,16 +290,16 @@ export class DoublyLinkedList {
|
|
|
290
290
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
291
291
|
* Space Complexity: O(1)
|
|
292
292
|
*
|
|
293
|
-
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or
|
|
293
|
+
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
294
294
|
* range.
|
|
295
295
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
296
296
|
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
297
297
|
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
298
|
-
* valid range of the linked list, otherwise it returns `
|
|
298
|
+
* valid range of the linked list, otherwise it returns `undefined`.
|
|
299
299
|
*/
|
|
300
300
|
getNodeAt(index) {
|
|
301
301
|
if (index < 0 || index >= this.length)
|
|
302
|
-
return
|
|
302
|
+
return undefined;
|
|
303
303
|
let current = this.head;
|
|
304
304
|
for (let i = 0; i < index; i++) {
|
|
305
305
|
current = current.next;
|
|
@@ -315,10 +315,10 @@ export class DoublyLinkedList {
|
|
|
315
315
|
* Space Complexity: O(1)
|
|
316
316
|
*
|
|
317
317
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
318
|
-
* node if found, otherwise it returns
|
|
318
|
+
* node if found, otherwise it returns undefined.
|
|
319
319
|
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
320
320
|
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
|
|
321
|
-
* is found in the linked list. If no such node is found, it returns `
|
|
321
|
+
* is found in the linked list. If no such node is found, it returns `undefined`.
|
|
322
322
|
*/
|
|
323
323
|
getNode(value) {
|
|
324
324
|
let current = this.head;
|
|
@@ -328,7 +328,7 @@ export class DoublyLinkedList {
|
|
|
328
328
|
}
|
|
329
329
|
current = current.next;
|
|
330
330
|
}
|
|
331
|
-
return
|
|
331
|
+
return undefined;
|
|
332
332
|
}
|
|
333
333
|
/**
|
|
334
334
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -459,7 +459,7 @@ export class DoublyLinkedList {
|
|
|
459
459
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
460
460
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
461
461
|
* data structure. It is of type number.
|
|
462
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `
|
|
462
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
463
463
|
* bounds.
|
|
464
464
|
*/
|
|
465
465
|
deleteAt(index) {
|
|
@@ -525,11 +525,11 @@ export class DoublyLinkedList {
|
|
|
525
525
|
return this.length === 0;
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
528
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to
|
|
528
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
529
529
|
*/
|
|
530
530
|
clear() {
|
|
531
|
-
this._head =
|
|
532
|
-
this._tail =
|
|
531
|
+
this._head = undefined;
|
|
532
|
+
this._tail = undefined;
|
|
533
533
|
this._length = 0;
|
|
534
534
|
}
|
|
535
535
|
/**
|
|
@@ -544,7 +544,7 @@ export class DoublyLinkedList {
|
|
|
544
544
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
545
545
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
546
546
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
547
|
-
* the callback function. If no element satisfies the condition, it returns `
|
|
547
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
548
548
|
*/
|
|
549
549
|
find(callback) {
|
|
550
550
|
let current = this.head;
|
|
@@ -554,7 +554,7 @@ export class DoublyLinkedList {
|
|
|
554
554
|
}
|
|
555
555
|
current = current.next;
|
|
556
556
|
}
|
|
557
|
-
return
|
|
557
|
+
return undefined;
|
|
558
558
|
}
|
|
559
559
|
/**
|
|
560
560
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -591,11 +591,11 @@ export class DoublyLinkedList {
|
|
|
591
591
|
* Space Complexity: O(1)
|
|
592
592
|
*
|
|
593
593
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
594
|
-
* value that satisfies the given callback function, or
|
|
594
|
+
* value that satisfies the given callback function, or undefined if no value satisfies the callback.
|
|
595
595
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
596
596
|
* function is used to determine whether a given value satisfies a certain condition.
|
|
597
597
|
* @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
|
|
598
|
-
* the callback function. If no value satisfies the condition, it returns `
|
|
598
|
+
* the callback function. If no value satisfies the condition, it returns `undefined`.
|
|
599
599
|
*/
|
|
600
600
|
findBackward(callback) {
|
|
601
601
|
let current = this.tail;
|
|
@@ -605,7 +605,7 @@ export class DoublyLinkedList {
|
|
|
605
605
|
}
|
|
606
606
|
current = current.prev;
|
|
607
607
|
}
|
|
608
|
-
return
|
|
608
|
+
return undefined;
|
|
609
609
|
}
|
|
610
610
|
/**
|
|
611
611
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|