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
|
@@ -11,19 +11,19 @@ exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
|
|
|
11
11
|
class DoublyLinkedListNode {
|
|
12
12
|
/**
|
|
13
13
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
14
|
-
* @param {E}
|
|
14
|
+
* @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
15
15
|
* is defined as a generic type "E".
|
|
16
16
|
*/
|
|
17
|
-
constructor(
|
|
18
|
-
this.
|
|
17
|
+
constructor(value) {
|
|
18
|
+
this._value = value;
|
|
19
19
|
this._next = null;
|
|
20
20
|
this._prev = null;
|
|
21
21
|
}
|
|
22
|
-
get
|
|
23
|
-
return this.
|
|
22
|
+
get value() {
|
|
23
|
+
return this._value;
|
|
24
24
|
}
|
|
25
|
-
set
|
|
26
|
-
this.
|
|
25
|
+
set value(value) {
|
|
26
|
+
this._value = value;
|
|
27
27
|
}
|
|
28
28
|
get next() {
|
|
29
29
|
return this._next;
|
|
@@ -81,10 +81,10 @@ class DoublyLinkedList {
|
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
84
|
-
* @param {E}
|
|
84
|
+
* @param {E} value - The value to be added to the linked list.
|
|
85
85
|
*/
|
|
86
|
-
push(
|
|
87
|
-
const newNode = new DoublyLinkedListNode(
|
|
86
|
+
push(value) {
|
|
87
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
88
88
|
if (!this.head) {
|
|
89
89
|
this.head = newNode;
|
|
90
90
|
this.tail = newNode;
|
|
@@ -98,14 +98,14 @@ class DoublyLinkedList {
|
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
100
|
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
101
|
-
* @param {E}
|
|
101
|
+
* @param {E} value - The value to be added to the linked list.
|
|
102
102
|
*/
|
|
103
|
-
addLast(
|
|
104
|
-
this.push(
|
|
103
|
+
addLast(value) {
|
|
104
|
+
this.push(value);
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
108
|
-
* @returns The method is returning the value of the removed node (removedNode.
|
|
108
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
109
109
|
* list is empty, it returns null.
|
|
110
110
|
*/
|
|
111
111
|
pop() {
|
|
@@ -121,11 +121,11 @@ class DoublyLinkedList {
|
|
|
121
121
|
this.tail.next = null;
|
|
122
122
|
}
|
|
123
123
|
this._length--;
|
|
124
|
-
return removedNode.
|
|
124
|
+
return removedNode.value;
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
128
|
-
* @returns The method is returning the value of the removed node (removedNode.
|
|
128
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
129
129
|
* list is empty, it returns null.
|
|
130
130
|
*/
|
|
131
131
|
popLast() {
|
|
@@ -149,7 +149,7 @@ class DoublyLinkedList {
|
|
|
149
149
|
this.head.prev = null;
|
|
150
150
|
}
|
|
151
151
|
this._length--;
|
|
152
|
-
return removedNode.
|
|
152
|
+
return removedNode.value;
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* The `popFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
@@ -161,11 +161,11 @@ class DoublyLinkedList {
|
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
164
|
-
* @param {E}
|
|
164
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
165
165
|
* doubly linked list.
|
|
166
166
|
*/
|
|
167
|
-
unshift(
|
|
168
|
-
const newNode = new DoublyLinkedListNode(
|
|
167
|
+
unshift(value) {
|
|
168
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
169
169
|
if (!this.head) {
|
|
170
170
|
this.head = newNode;
|
|
171
171
|
this.tail = newNode;
|
|
@@ -179,11 +179,11 @@ class DoublyLinkedList {
|
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
181
|
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
182
|
-
* @param {E}
|
|
182
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
183
183
|
* doubly linked list.
|
|
184
184
|
*/
|
|
185
|
-
addFirst(
|
|
186
|
-
this.unshift(
|
|
185
|
+
addFirst(value) {
|
|
186
|
+
this.unshift(value);
|
|
187
187
|
}
|
|
188
188
|
/**
|
|
189
189
|
* The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
@@ -191,7 +191,7 @@ class DoublyLinkedList {
|
|
|
191
191
|
*/
|
|
192
192
|
getFirst() {
|
|
193
193
|
var _a;
|
|
194
|
-
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.
|
|
194
|
+
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
197
|
* The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
@@ -199,7 +199,7 @@ class DoublyLinkedList {
|
|
|
199
199
|
*/
|
|
200
200
|
getLast() {
|
|
201
201
|
var _a;
|
|
202
|
-
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.
|
|
202
|
+
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
@@ -215,7 +215,7 @@ class DoublyLinkedList {
|
|
|
215
215
|
for (let i = 0; i < index; i++) {
|
|
216
216
|
current = current.next;
|
|
217
217
|
}
|
|
218
|
-
return current.
|
|
218
|
+
return current.value;
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
221
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
@@ -237,14 +237,14 @@ class DoublyLinkedList {
|
|
|
237
237
|
/**
|
|
238
238
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
239
239
|
* node if found, otherwise it returns null.
|
|
240
|
-
* @param {E}
|
|
241
|
-
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `
|
|
240
|
+
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
241
|
+
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
|
|
242
242
|
* is found in the linked list. If no such node is found, it returns `null`.
|
|
243
243
|
*/
|
|
244
|
-
getNode(
|
|
244
|
+
getNode(value) {
|
|
245
245
|
let current = this.head;
|
|
246
246
|
while (current) {
|
|
247
|
-
if (current.
|
|
247
|
+
if (current.value === value) {
|
|
248
248
|
return current;
|
|
249
249
|
}
|
|
250
250
|
current = current.next;
|
|
@@ -255,23 +255,23 @@ class DoublyLinkedList {
|
|
|
255
255
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
256
256
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
257
257
|
* DoublyLinkedList. It is of type number.
|
|
258
|
-
* @param {E}
|
|
258
|
+
* @param {E} value - The `value` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
259
259
|
* specified index.
|
|
260
260
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
261
261
|
* if the index is out of bounds.
|
|
262
262
|
*/
|
|
263
|
-
insertAt(index,
|
|
263
|
+
insertAt(index, value) {
|
|
264
264
|
if (index < 0 || index > this.length)
|
|
265
265
|
return false;
|
|
266
266
|
if (index === 0) {
|
|
267
|
-
this.unshift(
|
|
267
|
+
this.unshift(value);
|
|
268
268
|
return true;
|
|
269
269
|
}
|
|
270
270
|
if (index === this.length) {
|
|
271
|
-
this.push(
|
|
271
|
+
this.push(value);
|
|
272
272
|
return true;
|
|
273
273
|
}
|
|
274
|
-
const newNode = new DoublyLinkedListNode(
|
|
274
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
275
275
|
const prevNode = this.getNodeAt(index - 1);
|
|
276
276
|
const nextNode = prevNode.next;
|
|
277
277
|
newNode.prev = prevNode;
|
|
@@ -335,7 +335,7 @@ class DoublyLinkedList {
|
|
|
335
335
|
prevNode.next = nextNode;
|
|
336
336
|
nextNode.prev = prevNode;
|
|
337
337
|
this._length--;
|
|
338
|
-
return removedNode.
|
|
338
|
+
return removedNode.value;
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
341
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -378,7 +378,7 @@ class DoublyLinkedList {
|
|
|
378
378
|
const array = [];
|
|
379
379
|
let current = this.head;
|
|
380
380
|
while (current) {
|
|
381
|
-
array.push(current.
|
|
381
|
+
array.push(current.value);
|
|
382
382
|
current = current.next;
|
|
383
383
|
}
|
|
384
384
|
return array;
|
|
@@ -408,8 +408,8 @@ class DoublyLinkedList {
|
|
|
408
408
|
find(callback) {
|
|
409
409
|
let current = this.head;
|
|
410
410
|
while (current) {
|
|
411
|
-
if (callback(current.
|
|
412
|
-
return current.
|
|
411
|
+
if (callback(current.value)) {
|
|
412
|
+
return current.value;
|
|
413
413
|
}
|
|
414
414
|
current = current.next;
|
|
415
415
|
}
|
|
@@ -417,16 +417,16 @@ class DoublyLinkedList {
|
|
|
417
417
|
}
|
|
418
418
|
/**
|
|
419
419
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
420
|
-
* @param {E}
|
|
420
|
+
* @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value
|
|
421
421
|
* that we are searching for in the linked list.
|
|
422
|
-
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `
|
|
422
|
+
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `value` in the linked
|
|
423
423
|
* list. If the value is not found, it returns -1.
|
|
424
424
|
*/
|
|
425
|
-
indexOf(
|
|
425
|
+
indexOf(value) {
|
|
426
426
|
let index = 0;
|
|
427
427
|
let current = this.head;
|
|
428
428
|
while (current) {
|
|
429
|
-
if (current.
|
|
429
|
+
if (current.value === value) {
|
|
430
430
|
return index;
|
|
431
431
|
}
|
|
432
432
|
index++;
|
|
@@ -445,8 +445,8 @@ class DoublyLinkedList {
|
|
|
445
445
|
findBackward(callback) {
|
|
446
446
|
let current = this.tail;
|
|
447
447
|
while (current) {
|
|
448
|
-
if (callback(current.
|
|
449
|
-
return current.
|
|
448
|
+
if (callback(current.value)) {
|
|
449
|
+
return current.value;
|
|
450
450
|
}
|
|
451
451
|
current = current.prev;
|
|
452
452
|
}
|
|
@@ -460,7 +460,7 @@ class DoublyLinkedList {
|
|
|
460
460
|
const array = [];
|
|
461
461
|
let current = this.tail;
|
|
462
462
|
while (current) {
|
|
463
|
-
array.push(current.
|
|
463
|
+
array.push(current.value);
|
|
464
464
|
current = current.prev;
|
|
465
465
|
}
|
|
466
466
|
return array;
|
|
@@ -479,7 +479,7 @@ class DoublyLinkedList {
|
|
|
479
479
|
}
|
|
480
480
|
/**
|
|
481
481
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
482
|
-
* @param callback - The callback parameter is a function that takes two arguments:
|
|
482
|
+
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
483
483
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
484
484
|
* current node in the linked list.
|
|
485
485
|
*/
|
|
@@ -487,7 +487,7 @@ class DoublyLinkedList {
|
|
|
487
487
|
let current = this.head;
|
|
488
488
|
let index = 0;
|
|
489
489
|
while (current) {
|
|
490
|
-
callback(current.
|
|
490
|
+
callback(current.value, index);
|
|
491
491
|
current = current.next;
|
|
492
492
|
index++;
|
|
493
493
|
}
|
|
@@ -504,7 +504,7 @@ class DoublyLinkedList {
|
|
|
504
504
|
const mappedList = new DoublyLinkedList();
|
|
505
505
|
let current = this.head;
|
|
506
506
|
while (current) {
|
|
507
|
-
mappedList.push(callback(current.
|
|
507
|
+
mappedList.push(callback(current.value));
|
|
508
508
|
current = current.next;
|
|
509
509
|
}
|
|
510
510
|
return mappedList;
|
|
@@ -520,8 +520,8 @@ class DoublyLinkedList {
|
|
|
520
520
|
const filteredList = new DoublyLinkedList();
|
|
521
521
|
let current = this.head;
|
|
522
522
|
while (current) {
|
|
523
|
-
if (callback(current.
|
|
524
|
-
filteredList.push(current.
|
|
523
|
+
if (callback(current.value)) {
|
|
524
|
+
filteredList.push(current.value);
|
|
525
525
|
}
|
|
526
526
|
current = current.next;
|
|
527
527
|
}
|
|
@@ -530,7 +530,7 @@ class DoublyLinkedList {
|
|
|
530
530
|
/**
|
|
531
531
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
532
532
|
* single value.
|
|
533
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `
|
|
533
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
534
534
|
* used to perform a specific operation on each element of the linked list.
|
|
535
535
|
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
536
536
|
* point for the reduction operation.
|
|
@@ -541,7 +541,7 @@ class DoublyLinkedList {
|
|
|
541
541
|
let accumulator = initialValue;
|
|
542
542
|
let current = this.head;
|
|
543
543
|
while (current) {
|
|
544
|
-
accumulator = callback(accumulator, current.
|
|
544
|
+
accumulator = callback(accumulator, current.value);
|
|
545
545
|
current = current.next;
|
|
546
546
|
}
|
|
547
547
|
return accumulator;
|
|
@@ -585,7 +585,7 @@ class DoublyLinkedList {
|
|
|
585
585
|
*[Symbol.iterator]() {
|
|
586
586
|
let current = this.head;
|
|
587
587
|
while (current) {
|
|
588
|
-
yield current.
|
|
588
|
+
yield current.value;
|
|
589
589
|
current = current.next;
|
|
590
590
|
}
|
|
591
591
|
}
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
export declare class SinglyLinkedListNode<E = any> {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
11
|
-
* @param {E}
|
|
11
|
+
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
12
12
|
* will be stored in the node of a linked list.
|
|
13
13
|
*/
|
|
14
|
-
constructor(
|
|
15
|
-
private
|
|
16
|
-
get
|
|
17
|
-
set
|
|
14
|
+
constructor(value: E);
|
|
15
|
+
private _value;
|
|
16
|
+
get value(): E;
|
|
17
|
+
set value(value: E);
|
|
18
18
|
private _next;
|
|
19
19
|
get next(): SinglyLinkedListNode<E> | null;
|
|
20
20
|
set next(value: SinglyLinkedListNode<E> | null);
|
|
@@ -40,17 +40,17 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
40
40
|
*/
|
|
41
41
|
static fromArray<E>(data: E[]): SinglyLinkedList<E>;
|
|
42
42
|
/**
|
|
43
|
-
* The `push` function adds a new node with the given
|
|
44
|
-
* @param {E}
|
|
43
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
44
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
45
45
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
46
46
|
*/
|
|
47
|
-
push(
|
|
47
|
+
push(value: E): void;
|
|
48
48
|
/**
|
|
49
|
-
* The `push` function adds a new node with the given
|
|
50
|
-
* @param {E}
|
|
49
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
50
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
51
51
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
52
52
|
*/
|
|
53
|
-
addLast(
|
|
53
|
+
addLast(value: E): void;
|
|
54
54
|
/**
|
|
55
55
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
56
56
|
* pointers accordingly.
|
|
@@ -77,16 +77,16 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
77
77
|
popFirst(): E | undefined;
|
|
78
78
|
/**
|
|
79
79
|
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
80
|
-
* @param {E}
|
|
80
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
81
81
|
* linked list.
|
|
82
82
|
*/
|
|
83
|
-
unshift(
|
|
83
|
+
unshift(value: E): void;
|
|
84
84
|
/**
|
|
85
85
|
* The addFirst function adds a new node with the given value to the beginning of a singly linked list.
|
|
86
|
-
* @param {E}
|
|
86
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
87
87
|
* linked list.
|
|
88
88
|
*/
|
|
89
|
-
addFirst(
|
|
89
|
+
addFirst(value: E): void;
|
|
90
90
|
/**
|
|
91
91
|
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
92
92
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
@@ -123,12 +123,12 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
123
123
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
124
124
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
125
125
|
* linked list. It is of type number.
|
|
126
|
-
* @param {E}
|
|
126
|
+
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
127
127
|
* specified index.
|
|
128
128
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
129
129
|
* if the index is out of bounds.
|
|
130
130
|
*/
|
|
131
|
-
insertAt(index: number,
|
|
131
|
+
insertAt(index: number, value: E): boolean;
|
|
132
132
|
/**
|
|
133
133
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
134
134
|
* whether it is empty or not.
|
|
@@ -156,7 +156,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
156
156
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
157
157
|
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
158
158
|
*/
|
|
159
|
-
find(callback: (
|
|
159
|
+
find(callback: (value: E) => boolean): E | null;
|
|
160
160
|
/**
|
|
161
161
|
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
|
|
162
162
|
* @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
|
|
@@ -198,11 +198,11 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
198
198
|
countOccurrences(value: E): number;
|
|
199
199
|
/**
|
|
200
200
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
201
|
-
* @param callback - The callback parameter is a function that takes two arguments:
|
|
201
|
+
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
202
202
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
203
203
|
* current node in the linked list.
|
|
204
204
|
*/
|
|
205
|
-
forEach(callback: (
|
|
205
|
+
forEach(callback: (value: E, index: number) => void): void;
|
|
206
206
|
/**
|
|
207
207
|
* The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
|
|
208
208
|
* SinglyLinkedList with the transformed values.
|
|
@@ -211,7 +211,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
211
211
|
* SinglyLinkedList).
|
|
212
212
|
* @returns The `map` function is returning a new instance of `SinglyLinkedList<U>` that contains the mapped values.
|
|
213
213
|
*/
|
|
214
|
-
map<U>(callback: (
|
|
214
|
+
map<U>(callback: (value: E) => U): SinglyLinkedList<U>;
|
|
215
215
|
/**
|
|
216
216
|
* The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
|
|
217
217
|
* elements that satisfy the given callback function.
|
|
@@ -219,18 +219,18 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
219
219
|
* It is used to determine whether a value should be included in the filtered list or not.
|
|
220
220
|
* @returns The filtered list, which is an instance of the SinglyLinkedList class.
|
|
221
221
|
*/
|
|
222
|
-
filter(callback: (
|
|
222
|
+
filter(callback: (value: E) => boolean): SinglyLinkedList<E>;
|
|
223
223
|
/**
|
|
224
224
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
225
225
|
* single value.
|
|
226
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `
|
|
226
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
227
227
|
* used to perform a specific operation on each element of the linked list.
|
|
228
228
|
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
229
229
|
* point for the reduction operation.
|
|
230
230
|
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
231
231
|
* elements in the linked list.
|
|
232
232
|
*/
|
|
233
|
-
reduce<U>(callback: (accumulator: U,
|
|
233
|
+
reduce<U>(callback: (accumulator: U, value: E) => U, initialValue: U): U;
|
|
234
234
|
/**
|
|
235
235
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
236
236
|
*/
|