data-structure-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 (72) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +98 -17
  3. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
  4. package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
  5. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  6. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +22 -17
  7. package/dist/cjs/data-structures/graph/abstract-graph.js +71 -30
  8. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  9. package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
  10. package/dist/cjs/data-structures/graph/directed-graph.js +29 -29
  11. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
  13. package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
  14. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
  16. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
  17. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  18. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
  19. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
  20. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  21. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
  22. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  23. package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
  24. package/dist/cjs/data-structures/queue/queue.js +13 -13
  25. package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
  26. package/dist/cjs/data-structures/stack/stack.js +7 -7
  27. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  28. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
  29. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
  30. package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
  31. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +22 -17
  32. package/dist/mjs/data-structures/graph/abstract-graph.js +71 -30
  33. package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
  34. package/dist/mjs/data-structures/graph/directed-graph.js +29 -29
  35. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
  36. package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
  37. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
  38. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
  39. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
  40. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
  41. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
  42. package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
  43. package/dist/mjs/data-structures/queue/queue.js +13 -13
  44. package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
  45. package/dist/mjs/data-structures/stack/stack.js +7 -7
  46. package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
  47. package/dist/umd/data-structure-typed.js +203 -162
  48. package/dist/umd/data-structure-typed.min.js +2 -2
  49. package/dist/umd/data-structure-typed.min.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/data-structures/binary-tree/segment-tree.ts +10 -10
  52. package/src/data-structures/graph/abstract-graph.ts +92 -46
  53. package/src/data-structures/graph/directed-graph.ts +41 -41
  54. package/src/data-structures/graph/undirected-graph.ts +26 -26
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
  56. package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
  57. package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
  58. package/src/data-structures/queue/queue.ts +13 -13
  59. package/src/data-structures/stack/stack.ts +9 -9
  60. package/src/types/data-structures/graph/abstract-graph.ts +2 -2
  61. package/test/integration/index.html +102 -33
  62. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
  63. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
  64. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
  65. package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
  66. package/test/unit/data-structures/graph/directed-graph.test.ts +51 -10
  67. package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
  68. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  69. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
  70. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  71. package/test/unit/data-structures/queue/deque.test.ts +1 -1
  72. package/test/unit/data-structures/stack/stack.test.ts +2 -2
@@ -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
  /**
@@ -7,16 +7,16 @@
7
7
  */
8
8
  export class SinglyLinkedListNode<E = any> {
9
9
  value: E;
10
- next: SinglyLinkedListNode<E> | null;
10
+ next: SinglyLinkedListNode<E> | undefined;
11
11
 
12
12
  /**
13
- * The constructor function initializes an instance of a class with a given value and sets the next property to null.
13
+ * The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
14
14
  * @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
15
15
  * will be stored in the node of a linked list.
16
16
  */
17
17
  constructor(value: E) {
18
18
  this.value = value;
19
- this.next = null;
19
+ this.next = undefined;
20
20
  }
21
21
  }
22
22
 
@@ -25,8 +25,8 @@ export class SinglyLinkedList<E = any> {
25
25
  * The constructor initializes the linked list with an empty head, tail, and length.
26
26
  */
27
27
  constructor(elements?: Iterable<E>) {
28
- this._head = null;
29
- this._tail = null;
28
+ this._head = undefined;
29
+ this._tail = undefined;
30
30
  this._length = 0;
31
31
  if (elements) {
32
32
  for (const el of elements)
@@ -34,15 +34,15 @@ export class SinglyLinkedList<E = any> {
34
34
  }
35
35
  }
36
36
 
37
- protected _head: SinglyLinkedListNode<E> | null;
37
+ protected _head: SinglyLinkedListNode<E> | undefined;
38
38
 
39
- get head(): SinglyLinkedListNode<E> | null {
39
+ get head(): SinglyLinkedListNode<E> | undefined {
40
40
  return this._head;
41
41
  }
42
42
 
43
- protected _tail: SinglyLinkedListNode<E> | null;
43
+ protected _tail: SinglyLinkedListNode<E> | undefined;
44
44
 
45
- get tail(): SinglyLinkedListNode<E> | null {
45
+ get tail(): SinglyLinkedListNode<E> | undefined {
46
46
  return this._tail;
47
47
  }
48
48
 
@@ -128,14 +128,14 @@ export class SinglyLinkedList<E = any> {
128
128
  * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
129
129
  * pointers accordingly.
130
130
  * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
131
- * the linked list is empty, it returns `null`.
131
+ * the linked list is empty, it returns `undefined`.
132
132
  */
133
133
  pop(): E | undefined {
134
134
  if (!this.head) return undefined;
135
135
  if (this.head === this.tail) {
136
136
  const value = this.head.value;
137
- this._head = null;
138
- this._tail = null;
137
+ this._head = undefined;
138
+ this._tail = undefined;
139
139
  this._length--;
140
140
  return value;
141
141
  }
@@ -145,7 +145,7 @@ export class SinglyLinkedList<E = any> {
145
145
  current = current.next!;
146
146
  }
147
147
  const value = this.tail!.value;
148
- current.next = null;
148
+ current.next = undefined;
149
149
  this._tail = current;
150
150
  this._length--;
151
151
  return value;
@@ -163,7 +163,7 @@ export class SinglyLinkedList<E = any> {
163
163
  * The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
164
164
  * pointers accordingly.
165
165
  * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
166
- * the linked list is empty, it returns `null`.
166
+ * the linked list is empty, it returns `undefined`.
167
167
  */
168
168
  popLast(): E | undefined {
169
169
  return this.pop();
@@ -256,11 +256,11 @@ export class SinglyLinkedList<E = any> {
256
256
  * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
257
257
  * Space Complexity: O(1) - Constant space.
258
258
  *
259
- * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
259
+ * The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
260
260
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
261
261
  * retrieve from the list.
262
- * @returns The method `getAt(index: number): E | null` returns the value at the specified index in the linked list, or
263
- * `null` if the index is out of bounds.
262
+ * @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
263
+ * `undefined` if the index is out of bounds.
264
264
  */
265
265
  getAt(index: number): E | undefined {
266
266
  if (index < 0 || index >= this.length) return undefined;
@@ -284,9 +284,9 @@ export class SinglyLinkedList<E = any> {
284
284
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
285
285
  * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
286
286
  * @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
287
- * specified index exists, or `null` if the index is out of bounds.
287
+ * specified index exists, or `undefined` if the index is out of bounds.
288
288
  */
289
- getNodeAt(index: number): SinglyLinkedListNode<E> | null {
289
+ getNodeAt(index: number): SinglyLinkedListNode<E> | undefined {
290
290
  let current = this.head;
291
291
  for (let i = 0; i < index; i++) {
292
292
  current = current!.next;
@@ -306,7 +306,7 @@ export class SinglyLinkedList<E = any> {
306
306
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
307
307
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
308
308
  * data structure. It is of type number.
309
- * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
309
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
310
310
  * bounds.
311
311
  */
312
312
  deleteAt(index: number): E | undefined {
@@ -336,7 +336,7 @@ export class SinglyLinkedList<E = any> {
336
336
  * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
337
337
  * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
338
338
  */
339
- delete(valueOrNode: E | SinglyLinkedListNode<E> | null | undefined): boolean {
339
+ delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined | undefined): boolean {
340
340
  if (!valueOrNode) return false;
341
341
  let value: E;
342
342
  if (valueOrNode instanceof SinglyLinkedListNode) {
@@ -345,14 +345,14 @@ export class SinglyLinkedList<E = any> {
345
345
  value = valueOrNode;
346
346
  }
347
347
  let current = this.head,
348
- prev = null;
348
+ prev = undefined;
349
349
 
350
350
  while (current) {
351
351
  if (current.value === value) {
352
- if (prev === null) {
352
+ if (prev === undefined) {
353
353
  this._head = current.next;
354
354
  if (current === this.tail) {
355
- this._tail = null;
355
+ this._tail = undefined;
356
356
  }
357
357
  } else {
358
358
  prev.next = current.next;
@@ -416,11 +416,11 @@ export class SinglyLinkedList<E = any> {
416
416
  }
417
417
 
418
418
  /**
419
- * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
419
+ * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
420
420
  */
421
421
  clear(): void {
422
- this._head = null;
423
- this._tail = null;
422
+ this._head = undefined;
423
+ this._tail = undefined;
424
424
  this._length = 0;
425
425
  }
426
426
 
@@ -461,9 +461,9 @@ export class SinglyLinkedList<E = any> {
461
461
  reverse(): void {
462
462
  if (!this.head || this.head === this.tail) return;
463
463
 
464
- let prev: SinglyLinkedListNode<E> | null = null;
465
- let current: SinglyLinkedListNode<E> | null = this.head;
466
- let next: SinglyLinkedListNode<E> | null = null;
464
+ let prev: SinglyLinkedListNode<E> | undefined = undefined;
465
+ let current: SinglyLinkedListNode<E> | undefined = this.head;
466
+ let next: SinglyLinkedListNode<E> | undefined = undefined;
467
467
 
468
468
  while (current) {
469
469
  next = current.next;
@@ -488,9 +488,9 @@ export class SinglyLinkedList<E = any> {
488
488
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
489
489
  * function is used to determine whether a particular value in the linked list satisfies a certain condition.
490
490
  * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
491
- * the callback function. If no element satisfies the condition, it returns `null`.
491
+ * the callback function. If no element satisfies the condition, it returns `undefined`.
492
492
  */
493
- find(callback: (value: E) => boolean): E | null {
493
+ find(callback: (value: E) => boolean): E | undefined {
494
494
  let current = this.head;
495
495
  while (current) {
496
496
  if (callback(current.value)) {
@@ -498,7 +498,7 @@ export class SinglyLinkedList<E = any> {
498
498
  }
499
499
  current = current.next;
500
500
  }
501
- return null;
501
+ return undefined;
502
502
  }
503
503
 
504
504
  /**
@@ -540,12 +540,12 @@ export class SinglyLinkedList<E = any> {
540
540
  * Space Complexity: O(1) - Constant space.
541
541
  *
542
542
  * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
543
- * null.
543
+ * undefined.
544
544
  * @param {E} value - The value parameter is the value that we want to search for in the linked list.
545
545
  * @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
546
- * the specified value is found, the function returns `null`.
546
+ * the specified value is found, the function returns `undefined`.
547
547
  */
548
- getNode(value: E): SinglyLinkedListNode<E> | null {
548
+ getNode(value: E): SinglyLinkedListNode<E> | undefined {
549
549
  let current = this.head;
550
550
 
551
551
  while (current) {
@@ -555,7 +555,7 @@ export class SinglyLinkedList<E = any> {
555
555
  current = current.next;
556
556
  }
557
557
 
558
- return null;
558
+ return undefined;
559
559
  }
560
560
 
561
561
  /**
@@ -620,7 +620,7 @@ export class SinglyLinkedList<E = any> {
620
620
  * existing value or node, and false if the existing value or node was not found in the linked list.
621
621
  */
622
622
  insertAfter(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean {
623
- let existingNode: E | SinglyLinkedListNode<E> | null;
623
+ let existingNode: E | SinglyLinkedListNode<E> | undefined;
624
624
 
625
625
  if (existingValueOrNode instanceof SinglyLinkedListNode) {
626
626
  existingNode = existingValueOrNode;
@@ -27,7 +27,7 @@ export class SkipList<K, V> {
27
27
  * level in the skip list. It is used to determine the height of each node in the skip list.
28
28
  */
29
29
  constructor(maxLevel = 16, probability = 0.5) {
30
- this._head = new SkipListNode<K, V>(null as any, null as any, maxLevel);
30
+ this._head = new SkipListNode<K, V>(undefined as any, undefined as any, maxLevel);
31
31
  this._level = 0;
32
32
  this._maxLevel = maxLevel;
33
33
  this._probability = probability;
@@ -88,7 +88,7 @@ export class SkipList<K, V> {
88
88
  update[i].forward[i] = newNode;
89
89
  }
90
90
 
91
- if (newNode.forward[0] !== null) {
91
+ if (!newNode.forward[0]) {
92
92
  this._level = Math.max(this.level, newNode.forward.length);
93
93
  }
94
94
  }
@@ -172,7 +172,7 @@ export class SkipList<K, V> {
172
172
  }
173
173
  update[i].forward[i] = current.forward[i];
174
174
  }
175
- while (this.level > 0 && this.head.forward[this.level - 1] === null) {
175
+ while (this.level > 0 && !this.head.forward[this.level - 1]) {
176
176
  this._level--;
177
177
  }
178
178
  return true;
@@ -259,7 +259,7 @@ export class SkipList<K, V> {
259
259
  */
260
260
  lower(key: K): V | undefined {
261
261
  let current = this.head;
262
- let lastLess = null;
262
+ let lastLess = undefined;
263
263
 
264
264
  for (let i = this.level - 1; i >= 0; i--) {
265
265
  while (current.forward[i] && current.forward[i].key < key) {