data-structure-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/CHANGELOG.md +3 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +17 -17
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/bst.js +13 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +96 -96
- package/dist/cjs/data-structures/graph/abstract-graph.js +64 -64
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +68 -68
- package/dist/cjs/data-structures/graph/directed-graph.js +48 -48
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +13 -13
- package/dist/cjs/data-structures/graph/map-graph.js +15 -15
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +42 -42
- package/dist/cjs/data-structures/graph/undirected-graph.js +32 -32
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/cjs/data-structures/hash/hash-table.js +8 -8
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +54 -54
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +52 -52
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/data-structures/queue/queue.js +4 -4
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/interfaces/graph.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +18 -18
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.js +13 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +96 -96
- package/dist/mjs/data-structures/graph/abstract-graph.js +66 -66
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +68 -68
- package/dist/mjs/data-structures/graph/directed-graph.js +48 -48
- package/dist/mjs/data-structures/graph/map-graph.d.ts +13 -13
- package/dist/mjs/data-structures/graph/map-graph.js +15 -15
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +42 -42
- package/dist/mjs/data-structures/graph/undirected-graph.js +32 -32
- package/dist/mjs/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/mjs/data-structures/hash/hash-table.js +9 -9
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +55 -55
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +53 -53
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/queue/queue.js +4 -4
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/interfaces/graph.d.ts +3 -3
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- 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
- package/test/integration/bst.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +8 -8
- package/test/unit/data-structures/binary-tree/bst.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
- package/test/unit/data-structures/graph/abstract-graph.test.ts +99 -2
- package/test/unit/data-structures/graph/directed-graph.test.ts +38 -23
- package/test/unit/data-structures/graph/map-graph.test.ts +23 -23
- package/test/unit/data-structures/graph/undirected-graph.test.ts +10 -2
- package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +15 -15
- package/test/unit/data-structures/queue/queue.test.ts +8 -8
- package/test/utils/big-o.ts +7 -7
|
@@ -11,20 +11,20 @@ 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
|
-
|
|
23
|
-
get
|
|
24
|
-
return this.
|
|
22
|
+
_value;
|
|
23
|
+
get value() {
|
|
24
|
+
return this._value;
|
|
25
25
|
}
|
|
26
|
-
set
|
|
27
|
-
this.
|
|
26
|
+
set value(value) {
|
|
27
|
+
this._value = value;
|
|
28
28
|
}
|
|
29
29
|
_next;
|
|
30
30
|
get next() {
|
|
@@ -87,10 +87,10 @@ class DoublyLinkedList {
|
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
90
|
-
* @param {E}
|
|
90
|
+
* @param {E} value - The value to be added to the linked list.
|
|
91
91
|
*/
|
|
92
|
-
push(
|
|
93
|
-
const newNode = new DoublyLinkedListNode(
|
|
92
|
+
push(value) {
|
|
93
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
94
94
|
if (!this.head) {
|
|
95
95
|
this.head = newNode;
|
|
96
96
|
this.tail = newNode;
|
|
@@ -104,14 +104,14 @@ class DoublyLinkedList {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* The addLast 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
|
-
addLast(
|
|
110
|
-
this.push(
|
|
109
|
+
addLast(value) {
|
|
110
|
+
this.push(value);
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
114
|
-
* @returns The method is returning the value of the removed node (removedNode.
|
|
114
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
115
115
|
* list is empty, it returns null.
|
|
116
116
|
*/
|
|
117
117
|
pop() {
|
|
@@ -127,11 +127,11 @@ class DoublyLinkedList {
|
|
|
127
127
|
this.tail.next = null;
|
|
128
128
|
}
|
|
129
129
|
this._length--;
|
|
130
|
-
return removedNode.
|
|
130
|
+
return removedNode.value;
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
133
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
134
|
-
* @returns The method is returning the value of the removed node (removedNode.
|
|
134
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
135
135
|
* list is empty, it returns null.
|
|
136
136
|
*/
|
|
137
137
|
popLast() {
|
|
@@ -155,7 +155,7 @@ class DoublyLinkedList {
|
|
|
155
155
|
this.head.prev = null;
|
|
156
156
|
}
|
|
157
157
|
this._length--;
|
|
158
|
-
return removedNode.
|
|
158
|
+
return removedNode.value;
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* The `popFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
@@ -167,11 +167,11 @@ class DoublyLinkedList {
|
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
169
|
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
170
|
-
* @param {E}
|
|
170
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
171
171
|
* doubly linked list.
|
|
172
172
|
*/
|
|
173
|
-
unshift(
|
|
174
|
-
const newNode = new DoublyLinkedListNode(
|
|
173
|
+
unshift(value) {
|
|
174
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
175
175
|
if (!this.head) {
|
|
176
176
|
this.head = newNode;
|
|
177
177
|
this.tail = newNode;
|
|
@@ -185,25 +185,25 @@ class DoublyLinkedList {
|
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* The addFirst 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
|
-
addFirst(
|
|
192
|
-
this.unshift(
|
|
191
|
+
addFirst(value) {
|
|
192
|
+
this.unshift(value);
|
|
193
193
|
}
|
|
194
194
|
/**
|
|
195
195
|
* The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
196
196
|
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
197
197
|
*/
|
|
198
198
|
getFirst() {
|
|
199
|
-
return this.head?.
|
|
199
|
+
return this.head?.value;
|
|
200
200
|
}
|
|
201
201
|
/**
|
|
202
202
|
* The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
203
203
|
* @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
204
204
|
*/
|
|
205
205
|
getLast() {
|
|
206
|
-
return this.tail?.
|
|
206
|
+
return this.tail?.value;
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
@@ -219,7 +219,7 @@ class DoublyLinkedList {
|
|
|
219
219
|
for (let i = 0; i < index; i++) {
|
|
220
220
|
current = current.next;
|
|
221
221
|
}
|
|
222
|
-
return current.
|
|
222
|
+
return current.value;
|
|
223
223
|
}
|
|
224
224
|
/**
|
|
225
225
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
@@ -241,14 +241,14 @@ class DoublyLinkedList {
|
|
|
241
241
|
/**
|
|
242
242
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
243
243
|
* node if found, otherwise it returns null.
|
|
244
|
-
* @param {E}
|
|
245
|
-
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `
|
|
244
|
+
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
245
|
+
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
|
|
246
246
|
* is found in the linked list. If no such node is found, it returns `null`.
|
|
247
247
|
*/
|
|
248
|
-
getNode(
|
|
248
|
+
getNode(value) {
|
|
249
249
|
let current = this.head;
|
|
250
250
|
while (current) {
|
|
251
|
-
if (current.
|
|
251
|
+
if (current.value === value) {
|
|
252
252
|
return current;
|
|
253
253
|
}
|
|
254
254
|
current = current.next;
|
|
@@ -259,23 +259,23 @@ class DoublyLinkedList {
|
|
|
259
259
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
260
260
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
261
261
|
* DoublyLinkedList. It is of type number.
|
|
262
|
-
* @param {E}
|
|
262
|
+
* @param {E} value - The `value` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
263
263
|
* specified index.
|
|
264
264
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
265
265
|
* if the index is out of bounds.
|
|
266
266
|
*/
|
|
267
|
-
insertAt(index,
|
|
267
|
+
insertAt(index, value) {
|
|
268
268
|
if (index < 0 || index > this.length)
|
|
269
269
|
return false;
|
|
270
270
|
if (index === 0) {
|
|
271
|
-
this.unshift(
|
|
271
|
+
this.unshift(value);
|
|
272
272
|
return true;
|
|
273
273
|
}
|
|
274
274
|
if (index === this.length) {
|
|
275
|
-
this.push(
|
|
275
|
+
this.push(value);
|
|
276
276
|
return true;
|
|
277
277
|
}
|
|
278
|
-
const newNode = new DoublyLinkedListNode(
|
|
278
|
+
const newNode = new DoublyLinkedListNode(value);
|
|
279
279
|
const prevNode = this.getNodeAt(index - 1);
|
|
280
280
|
const nextNode = prevNode.next;
|
|
281
281
|
newNode.prev = prevNode;
|
|
@@ -339,7 +339,7 @@ class DoublyLinkedList {
|
|
|
339
339
|
prevNode.next = nextNode;
|
|
340
340
|
nextNode.prev = prevNode;
|
|
341
341
|
this._length--;
|
|
342
|
-
return removedNode.
|
|
342
|
+
return removedNode.value;
|
|
343
343
|
}
|
|
344
344
|
/**
|
|
345
345
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -382,7 +382,7 @@ class DoublyLinkedList {
|
|
|
382
382
|
const array = [];
|
|
383
383
|
let current = this.head;
|
|
384
384
|
while (current) {
|
|
385
|
-
array.push(current.
|
|
385
|
+
array.push(current.value);
|
|
386
386
|
current = current.next;
|
|
387
387
|
}
|
|
388
388
|
return array;
|
|
@@ -412,8 +412,8 @@ class DoublyLinkedList {
|
|
|
412
412
|
find(callback) {
|
|
413
413
|
let current = this.head;
|
|
414
414
|
while (current) {
|
|
415
|
-
if (callback(current.
|
|
416
|
-
return current.
|
|
415
|
+
if (callback(current.value)) {
|
|
416
|
+
return current.value;
|
|
417
417
|
}
|
|
418
418
|
current = current.next;
|
|
419
419
|
}
|
|
@@ -421,16 +421,16 @@ class DoublyLinkedList {
|
|
|
421
421
|
}
|
|
422
422
|
/**
|
|
423
423
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
424
|
-
* @param {E}
|
|
424
|
+
* @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value
|
|
425
425
|
* that we are searching for in the linked list.
|
|
426
|
-
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `
|
|
426
|
+
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `value` in the linked
|
|
427
427
|
* list. If the value is not found, it returns -1.
|
|
428
428
|
*/
|
|
429
|
-
indexOf(
|
|
429
|
+
indexOf(value) {
|
|
430
430
|
let index = 0;
|
|
431
431
|
let current = this.head;
|
|
432
432
|
while (current) {
|
|
433
|
-
if (current.
|
|
433
|
+
if (current.value === value) {
|
|
434
434
|
return index;
|
|
435
435
|
}
|
|
436
436
|
index++;
|
|
@@ -449,8 +449,8 @@ class DoublyLinkedList {
|
|
|
449
449
|
findBackward(callback) {
|
|
450
450
|
let current = this.tail;
|
|
451
451
|
while (current) {
|
|
452
|
-
if (callback(current.
|
|
453
|
-
return current.
|
|
452
|
+
if (callback(current.value)) {
|
|
453
|
+
return current.value;
|
|
454
454
|
}
|
|
455
455
|
current = current.prev;
|
|
456
456
|
}
|
|
@@ -464,7 +464,7 @@ class DoublyLinkedList {
|
|
|
464
464
|
const array = [];
|
|
465
465
|
let current = this.tail;
|
|
466
466
|
while (current) {
|
|
467
|
-
array.push(current.
|
|
467
|
+
array.push(current.value);
|
|
468
468
|
current = current.prev;
|
|
469
469
|
}
|
|
470
470
|
return array;
|
|
@@ -483,7 +483,7 @@ class DoublyLinkedList {
|
|
|
483
483
|
}
|
|
484
484
|
/**
|
|
485
485
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
486
|
-
* @param callback - The callback parameter is a function that takes two arguments:
|
|
486
|
+
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
487
487
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
488
488
|
* current node in the linked list.
|
|
489
489
|
*/
|
|
@@ -491,7 +491,7 @@ class DoublyLinkedList {
|
|
|
491
491
|
let current = this.head;
|
|
492
492
|
let index = 0;
|
|
493
493
|
while (current) {
|
|
494
|
-
callback(current.
|
|
494
|
+
callback(current.value, index);
|
|
495
495
|
current = current.next;
|
|
496
496
|
index++;
|
|
497
497
|
}
|
|
@@ -508,7 +508,7 @@ class DoublyLinkedList {
|
|
|
508
508
|
const mappedList = new DoublyLinkedList();
|
|
509
509
|
let current = this.head;
|
|
510
510
|
while (current) {
|
|
511
|
-
mappedList.push(callback(current.
|
|
511
|
+
mappedList.push(callback(current.value));
|
|
512
512
|
current = current.next;
|
|
513
513
|
}
|
|
514
514
|
return mappedList;
|
|
@@ -524,8 +524,8 @@ class DoublyLinkedList {
|
|
|
524
524
|
const filteredList = new DoublyLinkedList();
|
|
525
525
|
let current = this.head;
|
|
526
526
|
while (current) {
|
|
527
|
-
if (callback(current.
|
|
528
|
-
filteredList.push(current.
|
|
527
|
+
if (callback(current.value)) {
|
|
528
|
+
filteredList.push(current.value);
|
|
529
529
|
}
|
|
530
530
|
current = current.next;
|
|
531
531
|
}
|
|
@@ -534,7 +534,7 @@ class DoublyLinkedList {
|
|
|
534
534
|
/**
|
|
535
535
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
536
536
|
* single value.
|
|
537
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `
|
|
537
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
538
538
|
* used to perform a specific operation on each element of the linked list.
|
|
539
539
|
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
540
540
|
* point for the reduction operation.
|
|
@@ -545,7 +545,7 @@ class DoublyLinkedList {
|
|
|
545
545
|
let accumulator = initialValue;
|
|
546
546
|
let current = this.head;
|
|
547
547
|
while (current) {
|
|
548
|
-
accumulator = callback(accumulator, current.
|
|
548
|
+
accumulator = callback(accumulator, current.value);
|
|
549
549
|
current = current.next;
|
|
550
550
|
}
|
|
551
551
|
return accumulator;
|
|
@@ -589,7 +589,7 @@ class DoublyLinkedList {
|
|
|
589
589
|
*[Symbol.iterator]() {
|
|
590
590
|
let current = this.head;
|
|
591
591
|
while (current) {
|
|
592
|
-
yield current.
|
|
592
|
+
yield current.value;
|
|
593
593
|
current = current.next;
|
|
594
594
|
}
|
|
595
595
|
}
|
|
@@ -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
|
*/
|