min-heap-typed 1.39.4 → 1.39.6
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/avl-tree.d.ts +6 -6
- package/dist/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/data-structures/binary-tree/binary-tree.js +17 -17
- package/dist/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/data-structures/binary-tree/bst.js +13 -13
- package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/data-structures/graph/abstract-graph.d.ts +96 -96
- package/dist/data-structures/graph/abstract-graph.js +64 -64
- package/dist/data-structures/graph/directed-graph.d.ts +68 -68
- package/dist/data-structures/graph/directed-graph.js +48 -48
- package/dist/data-structures/graph/map-graph.d.ts +13 -13
- package/dist/data-structures/graph/map-graph.js +15 -15
- package/dist/data-structures/graph/undirected-graph.d.ts +42 -42
- package/dist/data-structures/graph/undirected-graph.js +32 -32
- package/dist/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/data-structures/hash/hash-table.js +8 -8
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/data-structures/linked-list/doubly-linked-list.js +54 -54
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +24 -24
- package/dist/data-structures/linked-list/singly-linked-list.js +52 -52
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/interfaces/binary-tree.d.ts +2 -2
- package/dist/interfaces/graph.d.ts +3 -3
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +13 -13
- package/src/data-structures/binary-tree/binary-tree.ts +18 -18
- package/src/data-structures/binary-tree/bst.ts +16 -16
- package/src/data-structures/binary-tree/rb-tree.ts +6 -6
- package/src/data-structures/binary-tree/segment-tree.ts +15 -15
- package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
- package/src/data-structures/graph/abstract-graph.ts +156 -154
- package/src/data-structures/graph/directed-graph.ts +99 -94
- package/src/data-structures/graph/map-graph.ts +22 -25
- package/src/data-structures/graph/undirected-graph.ts +62 -60
- package/src/data-structures/hash/hash-table.ts +9 -9
- package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
- package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
- package/src/data-structures/queue/queue.ts +2 -2
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +3 -3
|
@@ -8,23 +8,23 @@
|
|
|
8
8
|
export class DoublyLinkedListNode<E = any> {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
11
|
-
* @param {E}
|
|
11
|
+
* @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
12
12
|
* is defined as a generic type "E".
|
|
13
13
|
*/
|
|
14
|
-
constructor(
|
|
15
|
-
this.
|
|
14
|
+
constructor(value: E) {
|
|
15
|
+
this._value = value;
|
|
16
16
|
this._next = null;
|
|
17
17
|
this._prev = null;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
private
|
|
20
|
+
private _value: E;
|
|
21
21
|
|
|
22
|
-
get
|
|
23
|
-
return this.
|
|
22
|
+
get value(): E {
|
|
23
|
+
return this._value;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
set
|
|
27
|
-
this.
|
|
26
|
+
set value(value: E) {
|
|
27
|
+
this._value = value;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
private _next: DoublyLinkedListNode<E> | null;
|
|
@@ -104,10 +104,10 @@ export class DoublyLinkedList<E = any> {
|
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
107
|
-
* @param {E}
|
|
107
|
+
* @param {E} value - The value to be added to the linked list.
|
|
108
108
|
*/
|
|
109
|
-
push(
|
|
110
|
-
const newNode = new DoublyLinkedListNode(
|
|
109
|
+
push(value: E): void {
|
|
110
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
111
111
|
if (!this.head) {
|
|
112
112
|
this.head = newNode;
|
|
113
113
|
this.tail = newNode;
|
|
@@ -121,15 +121,15 @@ export class DoublyLinkedList<E = any> {
|
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
124
|
-
* @param {E}
|
|
124
|
+
* @param {E} value - The value to be added to the linked list.
|
|
125
125
|
*/
|
|
126
|
-
addLast(
|
|
127
|
-
this.push(
|
|
126
|
+
addLast(value: E): void {
|
|
127
|
+
this.push(value);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
132
|
-
* @returns The method is returning the value of the removed node (removedNode.
|
|
132
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
133
133
|
* list is empty, it returns null.
|
|
134
134
|
*/
|
|
135
135
|
pop(): E | undefined {
|
|
@@ -143,12 +143,12 @@ export class DoublyLinkedList<E = any> {
|
|
|
143
143
|
this.tail!.next = null;
|
|
144
144
|
}
|
|
145
145
|
this._length--;
|
|
146
|
-
return removedNode.
|
|
146
|
+
return removedNode.value;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
150
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
151
|
-
* @returns The method is returning the value of the removed node (removedNode.
|
|
151
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
152
152
|
* list is empty, it returns null.
|
|
153
153
|
*/
|
|
154
154
|
popLast(): E | undefined {
|
|
@@ -171,7 +171,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
171
171
|
this.head!.prev = null;
|
|
172
172
|
}
|
|
173
173
|
this._length--;
|
|
174
|
-
return removedNode.
|
|
174
|
+
return removedNode.value;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/**
|
|
@@ -185,11 +185,11 @@ export class DoublyLinkedList<E = any> {
|
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
187
|
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
188
|
-
* @param {E}
|
|
188
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
189
189
|
* doubly linked list.
|
|
190
190
|
*/
|
|
191
|
-
unshift(
|
|
192
|
-
const newNode = new DoublyLinkedListNode(
|
|
191
|
+
unshift(value: E): void {
|
|
192
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
193
193
|
if (!this.head) {
|
|
194
194
|
this.head = newNode;
|
|
195
195
|
this.tail = newNode;
|
|
@@ -203,11 +203,11 @@ export class DoublyLinkedList<E = any> {
|
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
205
|
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
206
|
-
* @param {E}
|
|
206
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
207
207
|
* doubly linked list.
|
|
208
208
|
*/
|
|
209
|
-
addFirst(
|
|
210
|
-
this.unshift(
|
|
209
|
+
addFirst(value: E): void {
|
|
210
|
+
this.unshift(value);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
/**
|
|
@@ -215,7 +215,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
215
215
|
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
216
216
|
*/
|
|
217
217
|
getFirst(): E | undefined {
|
|
218
|
-
return this.head?.
|
|
218
|
+
return this.head?.value;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
/**
|
|
@@ -223,7 +223,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
223
223
|
* @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
224
224
|
*/
|
|
225
225
|
getLast(): E | undefined {
|
|
226
|
-
return this.tail?.
|
|
226
|
+
return this.tail?.value;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
/**
|
|
@@ -239,7 +239,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
239
239
|
for (let i = 0; i < index; i++) {
|
|
240
240
|
current = current!.next;
|
|
241
241
|
}
|
|
242
|
-
return current!.
|
|
242
|
+
return current!.value;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
/**
|
|
@@ -262,15 +262,15 @@ export class DoublyLinkedList<E = any> {
|
|
|
262
262
|
/**
|
|
263
263
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
264
264
|
* node if found, otherwise it returns null.
|
|
265
|
-
* @param {E}
|
|
266
|
-
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `
|
|
265
|
+
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
266
|
+
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
|
|
267
267
|
* is found in the linked list. If no such node is found, it returns `null`.
|
|
268
268
|
*/
|
|
269
|
-
getNode(
|
|
269
|
+
getNode(value: E | null): DoublyLinkedListNode<E> | null {
|
|
270
270
|
let current = this.head;
|
|
271
271
|
|
|
272
272
|
while (current) {
|
|
273
|
-
if (current.
|
|
273
|
+
if (current.value === value) {
|
|
274
274
|
return current;
|
|
275
275
|
}
|
|
276
276
|
current = current.next;
|
|
@@ -283,23 +283,23 @@ export class DoublyLinkedList<E = any> {
|
|
|
283
283
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
284
284
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
285
285
|
* DoublyLinkedList. It is of type number.
|
|
286
|
-
* @param {E}
|
|
286
|
+
* @param {E} value - The `value` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
287
287
|
* specified index.
|
|
288
288
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
289
289
|
* if the index is out of bounds.
|
|
290
290
|
*/
|
|
291
|
-
insertAt(index: number,
|
|
291
|
+
insertAt(index: number, value: E): boolean {
|
|
292
292
|
if (index < 0 || index > this.length) return false;
|
|
293
293
|
if (index === 0) {
|
|
294
|
-
this.unshift(
|
|
294
|
+
this.unshift(value);
|
|
295
295
|
return true;
|
|
296
296
|
}
|
|
297
297
|
if (index === this.length) {
|
|
298
|
-
this.push(
|
|
298
|
+
this.push(value);
|
|
299
299
|
return true;
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
const newNode = new DoublyLinkedListNode(
|
|
302
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
303
303
|
const prevNode = this.getNodeAt(index - 1);
|
|
304
304
|
const nextNode = prevNode!.next;
|
|
305
305
|
newNode.prev = prevNode;
|
|
@@ -365,7 +365,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
365
365
|
prevNode!.next = nextNode;
|
|
366
366
|
nextNode!.prev = prevNode;
|
|
367
367
|
this._length--;
|
|
368
|
-
return removedNode!.
|
|
368
|
+
return removedNode!.value;
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
/**
|
|
@@ -409,7 +409,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
409
409
|
const array: E[] = [];
|
|
410
410
|
let current = this.head;
|
|
411
411
|
while (current) {
|
|
412
|
-
array.push(current.
|
|
412
|
+
array.push(current.value);
|
|
413
413
|
current = current.next;
|
|
414
414
|
}
|
|
415
415
|
return array;
|
|
@@ -439,11 +439,11 @@ export class DoublyLinkedList<E = any> {
|
|
|
439
439
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
440
440
|
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
441
441
|
*/
|
|
442
|
-
find(callback: (
|
|
442
|
+
find(callback: (value: E) => boolean): E | null {
|
|
443
443
|
let current = this.head;
|
|
444
444
|
while (current) {
|
|
445
|
-
if (callback(current.
|
|
446
|
-
return current.
|
|
445
|
+
if (callback(current.value)) {
|
|
446
|
+
return current.value;
|
|
447
447
|
}
|
|
448
448
|
current = current.next;
|
|
449
449
|
}
|
|
@@ -452,16 +452,16 @@ export class DoublyLinkedList<E = any> {
|
|
|
452
452
|
|
|
453
453
|
/**
|
|
454
454
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
455
|
-
* @param {E}
|
|
455
|
+
* @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value
|
|
456
456
|
* that we are searching for in the linked list.
|
|
457
|
-
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `
|
|
457
|
+
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `value` in the linked
|
|
458
458
|
* list. If the value is not found, it returns -1.
|
|
459
459
|
*/
|
|
460
|
-
indexOf(
|
|
460
|
+
indexOf(value: E): number {
|
|
461
461
|
let index = 0;
|
|
462
462
|
let current = this.head;
|
|
463
463
|
while (current) {
|
|
464
|
-
if (current.
|
|
464
|
+
if (current.value === value) {
|
|
465
465
|
return index;
|
|
466
466
|
}
|
|
467
467
|
index++;
|
|
@@ -478,11 +478,11 @@ export class DoublyLinkedList<E = any> {
|
|
|
478
478
|
* @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
|
|
479
479
|
* the callback function. If no value satisfies the condition, it returns `null`.
|
|
480
480
|
*/
|
|
481
|
-
findBackward(callback: (
|
|
481
|
+
findBackward(callback: (value: E) => boolean): E | null {
|
|
482
482
|
let current = this.tail;
|
|
483
483
|
while (current) {
|
|
484
|
-
if (callback(current.
|
|
485
|
-
return current.
|
|
484
|
+
if (callback(current.value)) {
|
|
485
|
+
return current.value;
|
|
486
486
|
}
|
|
487
487
|
current = current.prev;
|
|
488
488
|
}
|
|
@@ -497,7 +497,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
497
497
|
const array: E[] = [];
|
|
498
498
|
let current = this.tail;
|
|
499
499
|
while (current) {
|
|
500
|
-
array.push(current.
|
|
500
|
+
array.push(current.value);
|
|
501
501
|
current = current.prev;
|
|
502
502
|
}
|
|
503
503
|
return array;
|
|
@@ -518,15 +518,15 @@ export class DoublyLinkedList<E = any> {
|
|
|
518
518
|
|
|
519
519
|
/**
|
|
520
520
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
521
|
-
* @param callback - The callback parameter is a function that takes two arguments:
|
|
521
|
+
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
522
522
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
523
523
|
* current node in the linked list.
|
|
524
524
|
*/
|
|
525
|
-
forEach(callback: (
|
|
525
|
+
forEach(callback: (value: E, index: number) => void): void {
|
|
526
526
|
let current = this.head;
|
|
527
527
|
let index = 0;
|
|
528
528
|
while (current) {
|
|
529
|
-
callback(current.
|
|
529
|
+
callback(current.value, index);
|
|
530
530
|
current = current.next;
|
|
531
531
|
index++;
|
|
532
532
|
}
|
|
@@ -540,11 +540,11 @@ export class DoublyLinkedList<E = any> {
|
|
|
540
540
|
* DoublyLinkedList).
|
|
541
541
|
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
|
|
542
542
|
*/
|
|
543
|
-
map<U>(callback: (
|
|
543
|
+
map<U>(callback: (value: E) => U): DoublyLinkedList<U> {
|
|
544
544
|
const mappedList = new DoublyLinkedList<U>();
|
|
545
545
|
let current = this.head;
|
|
546
546
|
while (current) {
|
|
547
|
-
mappedList.push(callback(current.
|
|
547
|
+
mappedList.push(callback(current.value));
|
|
548
548
|
current = current.next;
|
|
549
549
|
}
|
|
550
550
|
return mappedList;
|
|
@@ -557,12 +557,12 @@ export class DoublyLinkedList<E = any> {
|
|
|
557
557
|
* It is used to determine whether a value should be included in the filtered list or not.
|
|
558
558
|
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
|
|
559
559
|
*/
|
|
560
|
-
filter(callback: (
|
|
560
|
+
filter(callback: (value: E) => boolean): DoublyLinkedList<E> {
|
|
561
561
|
const filteredList = new DoublyLinkedList<E>();
|
|
562
562
|
let current = this.head;
|
|
563
563
|
while (current) {
|
|
564
|
-
if (callback(current.
|
|
565
|
-
filteredList.push(current.
|
|
564
|
+
if (callback(current.value)) {
|
|
565
|
+
filteredList.push(current.value);
|
|
566
566
|
}
|
|
567
567
|
current = current.next;
|
|
568
568
|
}
|
|
@@ -572,18 +572,18 @@ export class DoublyLinkedList<E = any> {
|
|
|
572
572
|
/**
|
|
573
573
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
574
574
|
* single value.
|
|
575
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `
|
|
575
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
576
576
|
* used to perform a specific operation on each element of the linked list.
|
|
577
577
|
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
578
578
|
* point for the reduction operation.
|
|
579
579
|
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
580
580
|
* elements in the linked list.
|
|
581
581
|
*/
|
|
582
|
-
reduce<U>(callback: (accumulator: U,
|
|
582
|
+
reduce<U>(callback: (accumulator: U, value: E) => U, initialValue: U): U {
|
|
583
583
|
let accumulator = initialValue;
|
|
584
584
|
let current = this.head;
|
|
585
585
|
while (current) {
|
|
586
|
-
accumulator = callback(accumulator, current.
|
|
586
|
+
accumulator = callback(accumulator, current.value);
|
|
587
587
|
current = current.next;
|
|
588
588
|
}
|
|
589
589
|
return accumulator;
|
|
@@ -632,7 +632,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
632
632
|
let current = this.head;
|
|
633
633
|
|
|
634
634
|
while (current) {
|
|
635
|
-
yield current.
|
|
635
|
+
yield current.value;
|
|
636
636
|
current = current.next;
|
|
637
637
|
}
|
|
638
638
|
}
|