linked-list-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/dist/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/data-structures/graph/abstract-graph.js +30 -30
- package/dist/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/data-structures/graph/directed-graph.js +28 -28
- package/dist/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/data-structures/graph/undirected-graph.js +18 -18
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/data-structures/queue/queue.d.ts +13 -13
- package/dist/data-structures/queue/queue.js +13 -13
- package/dist/data-structures/stack/stack.d.ts +6 -6
- package/dist/data-structures/stack/stack.js +7 -7
- package/dist/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/package.json +2 -2
- 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
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export class SinglyLinkedListNode<E = any> {
|
|
9
9
|
value: E;
|
|
10
|
-
next: SinglyLinkedListNode<E> |
|
|
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
|
|
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 =
|
|
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 =
|
|
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)
|
|
@@ -34,15 +34,15 @@ export class SinglyLinkedList<E = any> {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
protected _head: SinglyLinkedListNode<E> |
|
|
37
|
+
protected _head: SinglyLinkedListNode<E> | undefined;
|
|
38
38
|
|
|
39
|
-
get head(): SinglyLinkedListNode<E> |
|
|
39
|
+
get head(): SinglyLinkedListNode<E> | undefined {
|
|
40
40
|
return this._head;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
protected _tail: SinglyLinkedListNode<E> |
|
|
43
|
+
protected _tail: SinglyLinkedListNode<E> | undefined;
|
|
44
44
|
|
|
45
|
-
get tail(): SinglyLinkedListNode<E> |
|
|
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 `
|
|
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 =
|
|
138
|
-
this._tail =
|
|
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 =
|
|
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 `
|
|
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
|
|
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 |
|
|
263
|
-
* `
|
|
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 `
|
|
287
|
+
* specified index exists, or `undefined` if the index is out of bounds.
|
|
288
288
|
*/
|
|
289
|
-
getNodeAt(index: number): SinglyLinkedListNode<E> |
|
|
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 `
|
|
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> |
|
|
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 =
|
|
348
|
+
prev = undefined;
|
|
349
349
|
|
|
350
350
|
while (current) {
|
|
351
351
|
if (current.value === value) {
|
|
352
|
-
if (prev ===
|
|
352
|
+
if (prev === undefined) {
|
|
353
353
|
this._head = current.next;
|
|
354
354
|
if (current === this.tail) {
|
|
355
|
-
this._tail =
|
|
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
|
|
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 =
|
|
423
|
-
this._tail =
|
|
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> |
|
|
465
|
-
let current: SinglyLinkedListNode<E> |
|
|
466
|
-
let next: SinglyLinkedListNode<E> |
|
|
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 `
|
|
491
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
492
492
|
*/
|
|
493
|
-
find(callback: (value: E) => boolean): E |
|
|
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
|
|
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
|
-
*
|
|
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 `
|
|
546
|
+
* the specified value is found, the function returns `undefined`.
|
|
547
547
|
*/
|
|
548
|
-
getNode(value: E): SinglyLinkedListNode<E> |
|
|
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
|
|
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> |
|
|
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>(
|
|
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]
|
|
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]
|
|
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 =
|
|
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) {
|
|
@@ -15,8 +15,8 @@ export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
19
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
18
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
19
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
20
20
|
*/
|
|
21
21
|
dequeue(): E | undefined {
|
|
22
22
|
return this.shift();
|
|
@@ -112,7 +112,7 @@ export class Queue<E = any> {
|
|
|
112
112
|
*
|
|
113
113
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
114
114
|
* necessary to optimize performance.
|
|
115
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
115
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
116
116
|
*/
|
|
117
117
|
shift(): E | undefined {
|
|
118
118
|
if (this.size === 0) return undefined;
|
|
@@ -138,9 +138,9 @@ export class Queue<E = any> {
|
|
|
138
138
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
139
139
|
* Space Complexity: O(1) - no additional space is used.
|
|
140
140
|
*
|
|
141
|
-
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
141
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
142
142
|
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
143
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
143
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
144
144
|
*/
|
|
145
145
|
getFirst(): E | undefined {
|
|
146
146
|
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
@@ -155,9 +155,9 @@ export class Queue<E = any> {
|
|
|
155
155
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
156
156
|
* Space Complexity: O(1) - no additional space is used.
|
|
157
157
|
*
|
|
158
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
158
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
159
159
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
160
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
160
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
161
161
|
*/
|
|
162
162
|
peek(): E | undefined {
|
|
163
163
|
return this.getFirst();
|
|
@@ -172,9 +172,9 @@ export class Queue<E = any> {
|
|
|
172
172
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
173
173
|
* Space Complexity: O(1) - no additional space is used.
|
|
174
174
|
*
|
|
175
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
175
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
176
176
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
177
|
-
* array is empty, it returns `
|
|
177
|
+
* array is empty, it returns `undefined`.
|
|
178
178
|
*/
|
|
179
179
|
getLast(): E | undefined {
|
|
180
180
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
@@ -189,9 +189,9 @@ export class Queue<E = any> {
|
|
|
189
189
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
190
190
|
* Space Complexity: O(1) - no additional space is used.
|
|
191
191
|
*
|
|
192
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
192
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
193
193
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
194
|
-
* array is empty, it returns `
|
|
194
|
+
* array is empty, it returns `undefined`.
|
|
195
195
|
*/
|
|
196
196
|
peekLast(): E | undefined {
|
|
197
197
|
return this.getLast();
|
|
@@ -222,8 +222,8 @@ export class Queue<E = any> {
|
|
|
222
222
|
* Time Complexity: O(n) - same as shift().
|
|
223
223
|
* Space Complexity: O(1) - same as shift().
|
|
224
224
|
*
|
|
225
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
226
|
-
* @returns The method is returning a value of type E or
|
|
225
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
226
|
+
* @returns The method is returning a value of type E or undefined.
|
|
227
227
|
*/
|
|
228
228
|
dequeue(): E | undefined {
|
|
229
229
|
return this.shift();
|
|
@@ -68,11 +68,11 @@ export class Stack<E = any> {
|
|
|
68
68
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
69
69
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
70
70
|
*
|
|
71
|
-
* The `peek` function returns the last element of an array, or
|
|
72
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
71
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
72
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
73
73
|
*/
|
|
74
|
-
peek(): E |
|
|
75
|
-
if (this.isEmpty()) return
|
|
74
|
+
peek(): E | undefined {
|
|
75
|
+
if (this.isEmpty()) return undefined;
|
|
76
76
|
|
|
77
77
|
return this.elements[this.elements.length - 1];
|
|
78
78
|
}
|
|
@@ -104,14 +104,14 @@ export class Stack<E = any> {
|
|
|
104
104
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
105
105
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
106
106
|
*
|
|
107
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
107
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
108
108
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
109
|
-
* array is empty, it returns `
|
|
109
|
+
* array is empty, it returns `undefined`.
|
|
110
110
|
*/
|
|
111
|
-
pop(): E |
|
|
112
|
-
if (this.isEmpty()) return
|
|
111
|
+
pop(): E | undefined {
|
|
112
|
+
if (this.isEmpty()) return undefined;
|
|
113
113
|
|
|
114
|
-
return this.elements.pop() ||
|
|
114
|
+
return this.elements.pop() || undefined;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
@@ -3,9 +3,9 @@ export type VertexKey = string | number;
|
|
|
3
3
|
export type DijkstraResult<V> = {
|
|
4
4
|
distMap: Map<V, number>;
|
|
5
5
|
distPaths?: Map<V, V[]>;
|
|
6
|
-
preMap: Map<V, V |
|
|
6
|
+
preMap: Map<V, V | undefined>;
|
|
7
7
|
seen: Set<V>;
|
|
8
8
|
paths: V[][];
|
|
9
9
|
minDist: number;
|
|
10
10
|
minPath: V[];
|
|
11
|
-
} |
|
|
11
|
+
} | undefined;
|