graph-typed 1.47.7 → 1.47.9

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.
Files changed (29) hide show
  1. package/dist/data-structures/binary-tree/segment-tree.d.ts +6 -6
  2. package/dist/data-structures/binary-tree/segment-tree.js +7 -7
  3. package/dist/data-structures/graph/abstract-graph.d.ts +22 -17
  4. package/dist/data-structures/graph/abstract-graph.js +71 -30
  5. package/dist/data-structures/graph/directed-graph.d.ts +24 -24
  6. package/dist/data-structures/graph/directed-graph.js +29 -29
  7. package/dist/data-structures/graph/undirected-graph.d.ts +14 -14
  8. package/dist/data-structures/graph/undirected-graph.js +18 -18
  9. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
  10. package/dist/data-structures/linked-list/doubly-linked-list.js +33 -33
  11. package/dist/data-structures/linked-list/singly-linked-list.d.ts +21 -21
  12. package/dist/data-structures/linked-list/singly-linked-list.js +27 -27
  13. package/dist/data-structures/linked-list/skip-linked-list.js +4 -4
  14. package/dist/data-structures/queue/queue.d.ts +13 -13
  15. package/dist/data-structures/queue/queue.js +13 -13
  16. package/dist/data-structures/stack/stack.d.ts +6 -6
  17. package/dist/data-structures/stack/stack.js +7 -7
  18. package/dist/types/data-structures/graph/abstract-graph.d.ts +2 -2
  19. package/package.json +2 -2
  20. package/src/data-structures/binary-tree/segment-tree.ts +10 -10
  21. package/src/data-structures/graph/abstract-graph.ts +92 -46
  22. package/src/data-structures/graph/directed-graph.ts +41 -41
  23. package/src/data-structures/graph/undirected-graph.ts +26 -26
  24. package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
  25. package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
  26. package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
  27. package/src/data-structures/queue/queue.ts +13 -13
  28. package/src/data-structures/stack/stack.ts +9 -9
  29. package/src/types/data-structures/graph/abstract-graph.ts +2 -2
@@ -87,7 +87,7 @@ export class DirectedGraph<
87
87
  * @returns a new instance of a DirectedVertex object, casted as type VO.
88
88
  */
89
89
  createVertex(key: VertexKey, value?: V): VO {
90
- return new DirectedVertex(key, value ?? key) as VO;
90
+ return new DirectedVertex(key, value) as VO;
91
91
  }
92
92
 
93
93
  /**
@@ -119,18 +119,18 @@ export class DirectedGraph<
119
119
  * Space Complexity: O(1)
120
120
  *
121
121
  * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
122
- * @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
123
- * @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
124
- * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
122
+ * @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
123
+ * @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
124
+ * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
125
125
  * destination is not specified.
126
- * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
126
+ * @returns the first edge found between the source and destination vertices, or undefined if no such edge is found.
127
127
  */
128
- getEdge(srcOrKey: VO | VertexKey | null, destOrKey: VO | VertexKey | null): EO | null {
128
+ getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined {
129
129
  let edges: EO[] = [];
130
130
 
131
- if (srcOrKey !== null && destOrKey !== null) {
132
- const src: VO | null = this._getVertex(srcOrKey);
133
- const dest: VO | null = this._getVertex(destOrKey);
131
+ if (srcOrKey !== undefined && destOrKey !== undefined) {
132
+ const src: VO | undefined = this._getVertex(srcOrKey);
133
+ const dest: VO | undefined = this._getVertex(destOrKey);
134
134
 
135
135
  if (src && dest) {
136
136
  const srcOutEdges = this._outEdgeMap.get(src);
@@ -140,7 +140,7 @@ export class DirectedGraph<
140
140
  }
141
141
  }
142
142
 
143
- return edges[0] || null;
143
+ return edges[0] || undefined;
144
144
  }
145
145
 
146
146
  /**
@@ -155,14 +155,14 @@ export class DirectedGraph<
155
155
  * The function removes an edge between two vertices in a graph and returns the removed edge.
156
156
  * @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
157
157
  * @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
158
- * @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
158
+ * @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
159
159
  */
160
- deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null {
161
- const src: VO | null = this._getVertex(srcOrKey);
162
- const dest: VO | null = this._getVertex(destOrKey);
163
- let removed: EO | null = null;
160
+ deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined {
161
+ const src: VO | undefined = this._getVertex(srcOrKey);
162
+ const dest: VO | undefined = this._getVertex(destOrKey);
163
+ let removed: EO | undefined = undefined;
164
164
  if (!src || !dest) {
165
- return null;
165
+ return undefined;
166
166
  }
167
167
 
168
168
  const srcOutEdges = this._outEdgeMap.get(src);
@@ -172,7 +172,7 @@ export class DirectedGraph<
172
172
 
173
173
  const destInEdges = this._inEdgeMap.get(dest);
174
174
  if (destInEdges) {
175
- removed = arrayRemove<EO>(destInEdges, (edge: EO) => edge.src === src.key)[0] || null;
175
+ removed = arrayRemove<EO>(destInEdges, (edge: EO) => edge.src === src.key)[0] || undefined;
176
176
  }
177
177
  return removed;
178
178
  }
@@ -186,13 +186,13 @@ export class DirectedGraph<
186
186
  * Time Complexity: O(|E|) where |E| is the number of edges
187
187
  * Space Complexity: O(1)
188
188
  *
189
- * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
189
+ * The function removes an edge from a graph and returns the removed edge, or undefined if the edge was not found.
190
190
  * @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
191
191
  * and `dest`, which represent the source and destination vertices of the edge, respectively.
192
- * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
192
+ * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `undefined` if the edge does not exist.
193
193
  */
194
- deleteEdge(edge: EO): EO | null {
195
- let removed: EO | null = null;
194
+ deleteEdge(edge: EO): EO | undefined {
195
+ let removed: EO | undefined = undefined;
196
196
  const src = this._getVertex(edge.src);
197
197
  const dest = this._getVertex(edge.dest);
198
198
  if (src && dest) {
@@ -361,11 +361,11 @@ export class DirectedGraph<
361
361
  * Time Complexity: O(1)
362
362
  * Space Complexity: O(1)
363
363
  *
364
- * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
364
+ * The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.
365
365
  * @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
366
- * @returns either a vertex object (VO) or null.
366
+ * @returns either a vertex object (VO) or undefined.
367
367
  */
368
- getEdgeSrc(e: EO): VO | null {
368
+ getEdgeSrc(e: EO): VO | undefined {
369
369
  return this._getVertex(e.src);
370
370
  }
371
371
 
@@ -380,9 +380,9 @@ export class DirectedGraph<
380
380
  *
381
381
  * The function "getEdgeDest" returns the destination vertex of an edge.
382
382
  * @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
383
- * @returns either a vertex object of type VO or null.
383
+ * @returns either a vertex object of type VO or undefined.
384
384
  */
385
- getEdgeDest(e: EO): VO | null {
385
+ getEdgeDest(e: EO): VO | undefined {
386
386
  return this._getVertex(e.dest);
387
387
  }
388
388
 
@@ -396,12 +396,12 @@ export class DirectedGraph<
396
396
  * Space Complexity: O(1)
397
397
  *
398
398
  * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
399
- * @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
400
- * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
399
+ * @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
400
+ * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
401
401
  * @returns an array of vertices (VO[]).
402
402
  */
403
- getDestinations(vertex: VO | VertexKey | null): VO[] {
404
- if (vertex === null) {
403
+ getDestinations(vertex: VO | VertexKey | undefined): VO[] {
404
+ if (vertex === undefined) {
405
405
  return [];
406
406
  }
407
407
  const destinations: VO[] = [];
@@ -425,13 +425,13 @@ export class DirectedGraph<
425
425
  * Space Complexity: O(|V|)
426
426
  *
427
427
  * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
428
- * in the sorted order, or null if the graph contains a cycle.
428
+ * in the sorted order, or undefined if the graph contains a cycle.
429
429
  * @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
430
430
  * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
431
431
  * specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
432
- * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
432
+ * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
433
433
  */
434
- topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | null {
434
+ topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined {
435
435
  propertyName = propertyName ?? 'key';
436
436
  // When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
437
437
  // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
@@ -463,7 +463,7 @@ export class DirectedGraph<
463
463
  }
464
464
  }
465
465
 
466
- if (hasCycle) return null;
466
+ if (hasCycle) return undefined;
467
467
 
468
468
  if (propertyName === 'key') sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
469
469
  return sorted.reverse();
@@ -510,7 +510,7 @@ export class DirectedGraph<
510
510
  const outEdges = this.outgoingEdgesOf(vertex);
511
511
  for (const outEdge of outEdges) {
512
512
  const neighbor = this._getVertex(outEdge.dest);
513
- // TODO after no-non-null-assertion not ensure the logic
513
+ // TODO after no-non-undefined-assertion not ensure the logic
514
514
  if (neighbor) {
515
515
  neighbors.push(neighbor);
516
516
  }
@@ -529,21 +529,21 @@ export class DirectedGraph<
529
529
  * Space Complexity: O(1)
530
530
  *
531
531
  * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
532
- * otherwise it returns null.
532
+ * otherwise it returns undefined.
533
533
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
534
534
  * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
535
- * graph. If the edge does not exist, it returns `null`.
535
+ * graph. If the edge does not exist, it returns `undefined`.
536
536
  */
537
- getEndsOfEdge(edge: EO): [VO, VO] | null {
537
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined {
538
538
  if (!this.hasEdge(edge.src, edge.dest)) {
539
- return null;
539
+ return undefined;
540
540
  }
541
541
  const v1 = this._getVertex(edge.src);
542
542
  const v2 = this._getVertex(edge.dest);
543
543
  if (v1 && v2) {
544
544
  return [v1, v2];
545
545
  } else {
546
- return null;
546
+ return undefined;
547
547
  }
548
548
  }
549
549
 
@@ -570,7 +570,7 @@ export class DirectedGraph<
570
570
  const srcVertex = this._getVertex(edge.src);
571
571
  const destVertex = this._getVertex(edge.dest);
572
572
 
573
- // TODO after no-non-null-assertion not ensure the logic
573
+ // TODO after no-non-undefined-assertion not ensure the logic
574
574
  if (srcVertex && destVertex) {
575
575
  const srcOutEdges = this._outEdgeMap.get(srcVertex);
576
576
  if (srcOutEdges) {
@@ -100,26 +100,26 @@ export class UndirectedGraph<
100
100
  * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
101
101
  * Space Complexity: O(1)
102
102
  *
103
- * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
104
- * @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
105
- * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
106
- * @param {VO | VertexKey | null} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
107
- * object), `null`, or `VertexKey` (vertex ID).
108
- * @returns an edge (EO) or null.
103
+ * The function `getEdge` returns the first edge that connects two vertices, or undefined if no such edge exists.
104
+ * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
105
+ * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
106
+ * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
107
+ * object), `undefined`, or `VertexKey` (vertex ID).
108
+ * @returns an edge (EO) or undefined.
109
109
  */
110
- getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null {
110
+ getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined {
111
111
  let edges: EO[] | undefined = [];
112
112
 
113
- if (v1 !== null && v2 !== null) {
114
- const vertex1: VO | null = this._getVertex(v1);
115
- const vertex2: VO | null = this._getVertex(v2);
113
+ if (v1 !== undefined && v2 !== undefined) {
114
+ const vertex1: VO | undefined = this._getVertex(v1);
115
+ const vertex2: VO | undefined = this._getVertex(v2);
116
116
 
117
117
  if (vertex1 && vertex2) {
118
118
  edges = this._edges.get(vertex1)?.filter(e => e.vertices.includes(vertex2.key));
119
119
  }
120
120
  }
121
121
 
122
- return edges ? edges[0] || null : null;
122
+ return edges ? edges[0] || undefined : undefined;
123
123
  }
124
124
 
125
125
  /**
@@ -135,20 +135,20 @@ export class UndirectedGraph<
135
135
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
136
136
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
137
137
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
138
- * @returns the removed edge (EO) if it exists, or null if either of the vertices (VO) does not exist.
138
+ * @returns the removed edge (EO) if it exists, or undefined if either of the vertices (VO) does not exist.
139
139
  */
140
- deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | null {
141
- const vertex1: VO | null = this._getVertex(v1);
142
- const vertex2: VO | null = this._getVertex(v2);
140
+ deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined {
141
+ const vertex1: VO | undefined = this._getVertex(v1);
142
+ const vertex2: VO | undefined = this._getVertex(v2);
143
143
 
144
144
  if (!vertex1 || !vertex2) {
145
- return null;
145
+ return undefined;
146
146
  }
147
147
 
148
148
  const v1Edges = this._edges.get(vertex1);
149
- let removed: EO | null = null;
149
+ let removed: EO | undefined = undefined;
150
150
  if (v1Edges) {
151
- removed = arrayRemove<EO>(v1Edges, (e: EO) => e.vertices.includes(vertex2.key))[0] || null;
151
+ removed = arrayRemove<EO>(v1Edges, (e: EO) => e.vertices.includes(vertex2.key))[0] || undefined;
152
152
  }
153
153
  const v2Edges = this._edges.get(vertex2);
154
154
  if (v2Edges) {
@@ -168,9 +168,9 @@ export class UndirectedGraph<
168
168
  *
169
169
  * The deleteEdge function removes an edge between two vertices in a graph.
170
170
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
171
- * @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
171
+ * @returns The method is returning either the removed edge (of type EO) or undefined if the edge was not found.
172
172
  */
173
- deleteEdge(edge: EO): EO | null {
173
+ deleteEdge(edge: EO): EO | undefined {
174
174
  return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
175
175
  }
176
176
 
@@ -282,21 +282,21 @@ export class UndirectedGraph<
282
282
  * Space Complexity: O(1)
283
283
  *
284
284
  * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
285
- * it returns null.
285
+ * it returns undefined.
286
286
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
287
287
  * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
288
- * graph. If the edge does not exist, it returns `null`.
288
+ * graph. If the edge does not exist, it returns `undefined`.
289
289
  */
290
- getEndsOfEdge(edge: EO): [VO, VO] | null {
290
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined {
291
291
  if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
292
- return null;
292
+ return undefined;
293
293
  }
294
294
  const v1 = this._getVertex(edge.vertices[0]);
295
295
  const v2 = this._getVertex(edge.vertices[1]);
296
296
  if (v1 && v2) {
297
297
  return [v1, v2];
298
298
  } else {
299
- return null;
299
+ return undefined;
300
300
  }
301
301
  }
302
302
 
@@ -316,7 +316,7 @@ export class UndirectedGraph<
316
316
  protected _addEdgeOnly(edge: EO): boolean {
317
317
  for (const end of edge.vertices) {
318
318
  const endVertex = this._getVertex(end);
319
- if (endVertex === null) return false;
319
+ if (endVertex === undefined) return false;
320
320
  if (endVertex) {
321
321
  const edges = this._edges.get(endVertex);
322
322
  if (edges) {
@@ -7,8 +7,8 @@
7
7
  */
8
8
  export class DoublyLinkedListNode<E = any> {
9
9
  value: E;
10
- next: DoublyLinkedListNode<E> | null;
11
- prev: DoublyLinkedListNode<E> | null;
10
+ next: DoublyLinkedListNode<E> | undefined;
11
+ prev: DoublyLinkedListNode<E> | undefined;
12
12
 
13
13
  /**
14
14
  * The constructor function initializes the value, next, and previous properties of an object.
@@ -17,8 +17,8 @@ export class DoublyLinkedListNode<E = any> {
17
17
  */
18
18
  constructor(value: E) {
19
19
  this.value = value;
20
- this.next = null;
21
- this.prev = null;
20
+ this.next = undefined;
21
+ this.prev = undefined;
22
22
  }
23
23
  }
24
24
 
@@ -27,8 +27,8 @@ export class DoublyLinkedList<E = any> {
27
27
  * The constructor initializes the linked list with an empty head, tail, and length.
28
28
  */
29
29
  constructor(elements?: Iterable<E>) {
30
- this._head = null;
31
- this._tail = null;
30
+ this._head = undefined;
31
+ this._tail = undefined;
32
32
  this._length = 0;
33
33
  if (elements) {
34
34
  for (const el of elements) {
@@ -37,15 +37,15 @@ export class DoublyLinkedList<E = any> {
37
37
  }
38
38
  }
39
39
 
40
- protected _head: DoublyLinkedListNode<E> | null;
40
+ protected _head: DoublyLinkedListNode<E> | undefined;
41
41
 
42
- get head(): DoublyLinkedListNode<E> | null {
42
+ get head(): DoublyLinkedListNode<E> | undefined {
43
43
  return this._head;
44
44
  }
45
45
 
46
- protected _tail: DoublyLinkedListNode<E> | null;
46
+ protected _tail: DoublyLinkedListNode<E> | undefined;
47
47
 
48
- get tail(): DoublyLinkedListNode<E> | null {
48
+ get tail(): DoublyLinkedListNode<E> | undefined {
49
49
  return this._tail;
50
50
  }
51
51
 
@@ -133,17 +133,17 @@ export class DoublyLinkedList<E = any> {
133
133
  *
134
134
  * The `pop()` function removes and returns the value of the last node in a doubly linked list.
135
135
  * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
136
- * list is empty, it returns null.
136
+ * list is empty, it returns undefined.
137
137
  */
138
138
  pop(): E | undefined {
139
139
  if (!this.tail) return undefined;
140
140
  const removedNode = this.tail;
141
141
  if (this.head === this.tail) {
142
- this._head = null;
143
- this._tail = null;
142
+ this._head = undefined;
143
+ this._tail = undefined;
144
144
  } else {
145
145
  this._tail = removedNode.prev;
146
- this.tail!.next = null;
146
+ this.tail!.next = undefined;
147
147
  }
148
148
  this._length--;
149
149
  return removedNode.value;
@@ -160,7 +160,7 @@ export class DoublyLinkedList<E = any> {
160
160
  *
161
161
  * The `popLast()` function removes and returns the value of the last node in a doubly linked list.
162
162
  * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
163
- * list is empty, it returns null.
163
+ * list is empty, it returns undefined.
164
164
  */
165
165
  popLast(): E | undefined {
166
166
  return this.pop();
@@ -183,11 +183,11 @@ export class DoublyLinkedList<E = any> {
183
183
  if (!this.head) return undefined;
184
184
  const removedNode = this.head;
185
185
  if (this.head === this.tail) {
186
- this._head = null;
187
- this._tail = null;
186
+ this._head = undefined;
187
+ this._tail = undefined;
188
188
  } else {
189
189
  this._head = removedNode.next;
190
- this.head!.prev = null;
190
+ this.head!.prev = undefined;
191
191
  }
192
192
  this._length--;
193
193
  return removedNode.value;
@@ -262,8 +262,8 @@ export class DoublyLinkedList<E = any> {
262
262
  * Time Complexity: O(n), where n is the number of elements in the linked list.
263
263
  * Space Complexity: O(1)
264
264
  *
265
- * The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
266
- * @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
265
+ * The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
266
+ * @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
267
267
  */
268
268
  getFirst(): E | undefined {
269
269
  return this.head?.value;
@@ -278,8 +278,8 @@ export class DoublyLinkedList<E = any> {
278
278
  * Time Complexity: O(n), where n is the number of elements in the linked list.
279
279
  * Space Complexity: O(1)
280
280
  *
281
- * The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
282
- * @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
281
+ * The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
282
+ * @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
283
283
  */
284
284
  getLast(): E | undefined {
285
285
  return this.tail?.value;
@@ -294,11 +294,11 @@ export class DoublyLinkedList<E = any> {
294
294
  * Time Complexity: O(n), where n is the number of elements in the linked list.
295
295
  * Space Complexity: O(1)
296
296
  *
297
- * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
297
+ * The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
298
298
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
299
299
  * retrieve from the list.
300
300
  * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
301
- * or the linked list is empty, it will return null.
301
+ * or the linked list is empty, it will return undefined.
302
302
  */
303
303
  getAt(index: number): E | undefined {
304
304
  if (index < 0 || index >= this.length) return undefined;
@@ -318,15 +318,15 @@ export class DoublyLinkedList<E = any> {
318
318
  * Time Complexity: O(n), where n is the number of elements in the linked list.
319
319
  * Space Complexity: O(1)
320
320
  *
321
- * The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
321
+ * The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
322
322
  * range.
323
323
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
324
324
  * retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
325
325
  * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
326
- * valid range of the linked list, otherwise it returns `null`.
326
+ * valid range of the linked list, otherwise it returns `undefined`.
327
327
  */
328
- getNodeAt(index: number): DoublyLinkedListNode<E> | null {
329
- if (index < 0 || index >= this.length) return null;
328
+ getNodeAt(index: number): DoublyLinkedListNode<E> | undefined {
329
+ if (index < 0 || index >= this.length) return undefined;
330
330
  let current = this.head;
331
331
  for (let i = 0; i < index; i++) {
332
332
  current = current!.next;
@@ -344,12 +344,12 @@ export class DoublyLinkedList<E = any> {
344
344
  * Space Complexity: O(1)
345
345
  *
346
346
  * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
347
- * node if found, otherwise it returns null.
347
+ * node if found, otherwise it returns undefined.
348
348
  * @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
349
349
  * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
350
- * is found in the linked list. If no such node is found, it returns `null`.
350
+ * is found in the linked list. If no such node is found, it returns `undefined`.
351
351
  */
352
- getNode(value: E | null): DoublyLinkedListNode<E> | null {
352
+ getNode(value: E | undefined): DoublyLinkedListNode<E> | undefined {
353
353
  let current = this.head;
354
354
 
355
355
  while (current) {
@@ -359,7 +359,7 @@ export class DoublyLinkedList<E = any> {
359
359
  current = current.next;
360
360
  }
361
361
 
362
- return null;
362
+ return undefined;
363
363
  }
364
364
 
365
365
  /**
@@ -502,7 +502,7 @@ export class DoublyLinkedList<E = any> {
502
502
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
503
503
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
504
504
  * data structure. It is of type number.
505
- * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
505
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
506
506
  * bounds.
507
507
  */
508
508
  deleteAt(index: number): E | undefined {
@@ -534,8 +534,8 @@ export class DoublyLinkedList<E = any> {
534
534
  * @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
535
535
  * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
536
536
  */
537
- delete(valOrNode: E | DoublyLinkedListNode<E> | null): boolean {
538
- let node: DoublyLinkedListNode<E> | null;
537
+ delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean {
538
+ let node: DoublyLinkedListNode<E> | undefined;
539
539
 
540
540
  if (valOrNode instanceof DoublyLinkedListNode) {
541
541
  node = valOrNode;
@@ -569,11 +569,11 @@ export class DoublyLinkedList<E = any> {
569
569
  }
570
570
 
571
571
  /**
572
- * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
572
+ * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
573
573
  */
574
574
  clear(): void {
575
- this._head = null;
576
- this._tail = null;
575
+ this._head = undefined;
576
+ this._tail = undefined;
577
577
  this._length = 0;
578
578
  }
579
579
 
@@ -590,9 +590,9 @@ export class DoublyLinkedList<E = any> {
590
590
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
591
591
  * function is used to determine whether a particular value in the linked list satisfies a certain condition.
592
592
  * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
593
- * the callback function. If no element satisfies the condition, it returns `null`.
593
+ * the callback function. If no element satisfies the condition, it returns `undefined`.
594
594
  */
595
- find(callback: (value: E) => boolean): E | null {
595
+ find(callback: (value: E) => boolean): E | undefined {
596
596
  let current = this.head;
597
597
  while (current) {
598
598
  if (callback(current.value)) {
@@ -600,7 +600,7 @@ export class DoublyLinkedList<E = any> {
600
600
  }
601
601
  current = current.next;
602
602
  }
603
- return null;
603
+ return undefined;
604
604
  }
605
605
 
606
606
  /**
@@ -641,13 +641,13 @@ export class DoublyLinkedList<E = any> {
641
641
  * Space Complexity: O(1)
642
642
  *
643
643
  * The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
644
- * value that satisfies the given callback function, or null if no value satisfies the callback.
644
+ * value that satisfies the given callback function, or undefined if no value satisfies the callback.
645
645
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
646
646
  * function is used to determine whether a given value satisfies a certain condition.
647
647
  * @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
648
- * the callback function. If no value satisfies the condition, it returns `null`.
648
+ * the callback function. If no value satisfies the condition, it returns `undefined`.
649
649
  */
650
- findBackward(callback: (value: E) => boolean): E | null {
650
+ findBackward(callback: (value: E) => boolean): E | undefined {
651
651
  let current = this.tail;
652
652
  while (current) {
653
653
  if (callback(current.value)) {
@@ -655,7 +655,7 @@ export class DoublyLinkedList<E = any> {
655
655
  }
656
656
  current = current.prev;
657
657
  }
658
- return null;
658
+ return undefined;
659
659
  }
660
660
 
661
661
  /**