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,19 +11,19 @@ exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
|
|
|
11
11
|
class SinglyLinkedListNode {
|
|
12
12
|
/**
|
|
13
13
|
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
14
|
-
* @param {E}
|
|
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
|
-
constructor(
|
|
18
|
-
this.
|
|
17
|
+
constructor(value) {
|
|
18
|
+
this._value = value;
|
|
19
19
|
this._next = null;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
get
|
|
23
|
-
return this.
|
|
21
|
+
_value;
|
|
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
|
_next;
|
|
29
29
|
get next() {
|
|
@@ -75,12 +75,12 @@ class SinglyLinkedList {
|
|
|
75
75
|
return singlyLinkedList;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
* The `push` function adds a new node with the given
|
|
79
|
-
* @param {E}
|
|
78
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
79
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
80
80
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
81
81
|
*/
|
|
82
|
-
push(
|
|
83
|
-
const newNode = new SinglyLinkedListNode(
|
|
82
|
+
push(value) {
|
|
83
|
+
const newNode = new SinglyLinkedListNode(value);
|
|
84
84
|
if (!this.head) {
|
|
85
85
|
this.head = newNode;
|
|
86
86
|
this.tail = newNode;
|
|
@@ -92,12 +92,12 @@ class SinglyLinkedList {
|
|
|
92
92
|
this._length++;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* The `push` function adds a new node with the given
|
|
96
|
-
* @param {E}
|
|
95
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
96
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
97
97
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
98
98
|
*/
|
|
99
|
-
addLast(
|
|
100
|
-
this.push(
|
|
99
|
+
addLast(value) {
|
|
100
|
+
this.push(value);
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
@@ -109,21 +109,21 @@ class SinglyLinkedList {
|
|
|
109
109
|
if (!this.head)
|
|
110
110
|
return undefined;
|
|
111
111
|
if (this.head === this.tail) {
|
|
112
|
-
const
|
|
112
|
+
const value = this.head.value;
|
|
113
113
|
this.head = null;
|
|
114
114
|
this.tail = null;
|
|
115
115
|
this._length--;
|
|
116
|
-
return
|
|
116
|
+
return value;
|
|
117
117
|
}
|
|
118
118
|
let current = this.head;
|
|
119
119
|
while (current.next !== this.tail) {
|
|
120
120
|
current = current.next;
|
|
121
121
|
}
|
|
122
|
-
const
|
|
122
|
+
const value = this.tail.value;
|
|
123
123
|
current.next = null;
|
|
124
124
|
this.tail = current;
|
|
125
125
|
this._length--;
|
|
126
|
-
return
|
|
126
|
+
return value;
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
129
|
* The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
@@ -144,7 +144,7 @@ class SinglyLinkedList {
|
|
|
144
144
|
const removedNode = this.head;
|
|
145
145
|
this.head = this.head.next;
|
|
146
146
|
this._length--;
|
|
147
|
-
return removedNode.
|
|
147
|
+
return removedNode.value;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* The `popFirst()` function removes and returns the value of the first node in a linked list.
|
|
@@ -155,11 +155,11 @@ class SinglyLinkedList {
|
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
158
|
-
* @param {E}
|
|
158
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
159
159
|
* linked list.
|
|
160
160
|
*/
|
|
161
|
-
unshift(
|
|
162
|
-
const newNode = new SinglyLinkedListNode(
|
|
161
|
+
unshift(value) {
|
|
162
|
+
const newNode = new SinglyLinkedListNode(value);
|
|
163
163
|
if (!this.head) {
|
|
164
164
|
this.head = newNode;
|
|
165
165
|
this.tail = newNode;
|
|
@@ -172,11 +172,11 @@ class SinglyLinkedList {
|
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* The addFirst function adds a new node with the given value to the beginning of a singly linked list.
|
|
175
|
-
* @param {E}
|
|
175
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
176
176
|
* linked list.
|
|
177
177
|
*/
|
|
178
|
-
addFirst(
|
|
179
|
-
this.unshift(
|
|
178
|
+
addFirst(value) {
|
|
179
|
+
this.unshift(value);
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
@@ -192,7 +192,7 @@ class SinglyLinkedList {
|
|
|
192
192
|
for (let i = 0; i < index; i++) {
|
|
193
193
|
current = current.next;
|
|
194
194
|
}
|
|
195
|
-
return current.
|
|
195
|
+
return current.value;
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
198
|
* The function `getNodeAt` returns the node at a given index in a singly linked list.
|
|
@@ -226,7 +226,7 @@ class SinglyLinkedList {
|
|
|
226
226
|
const removedNode = prevNode.next;
|
|
227
227
|
prevNode.next = removedNode.next;
|
|
228
228
|
this._length--;
|
|
229
|
-
return removedNode.
|
|
229
|
+
return removedNode.value;
|
|
230
230
|
}
|
|
231
231
|
/**
|
|
232
232
|
* The delete function removes a node with a specific value from a singly linked list.
|
|
@@ -240,14 +240,14 @@ class SinglyLinkedList {
|
|
|
240
240
|
return false;
|
|
241
241
|
let value;
|
|
242
242
|
if (valueOrNode instanceof SinglyLinkedListNode) {
|
|
243
|
-
value = valueOrNode.
|
|
243
|
+
value = valueOrNode.value;
|
|
244
244
|
}
|
|
245
245
|
else {
|
|
246
246
|
value = valueOrNode;
|
|
247
247
|
}
|
|
248
248
|
let current = this.head, prev = null;
|
|
249
249
|
while (current) {
|
|
250
|
-
if (current.
|
|
250
|
+
if (current.value === value) {
|
|
251
251
|
if (prev === null) {
|
|
252
252
|
this.head = current.next;
|
|
253
253
|
if (current === this.tail) {
|
|
@@ -272,23 +272,23 @@ class SinglyLinkedList {
|
|
|
272
272
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
273
273
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
274
274
|
* linked list. It is of type number.
|
|
275
|
-
* @param {E}
|
|
275
|
+
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
276
276
|
* specified index.
|
|
277
277
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
278
278
|
* if the index is out of bounds.
|
|
279
279
|
*/
|
|
280
|
-
insertAt(index,
|
|
280
|
+
insertAt(index, value) {
|
|
281
281
|
if (index < 0 || index > this.length)
|
|
282
282
|
return false;
|
|
283
283
|
if (index === 0) {
|
|
284
|
-
this.unshift(
|
|
284
|
+
this.unshift(value);
|
|
285
285
|
return true;
|
|
286
286
|
}
|
|
287
287
|
if (index === this.length) {
|
|
288
|
-
this.push(
|
|
288
|
+
this.push(value);
|
|
289
289
|
return true;
|
|
290
290
|
}
|
|
291
|
-
const newNode = new SinglyLinkedListNode(
|
|
291
|
+
const newNode = new SinglyLinkedListNode(value);
|
|
292
292
|
const prevNode = this.getNodeAt(index - 1);
|
|
293
293
|
newNode.next = prevNode.next;
|
|
294
294
|
prevNode.next = newNode;
|
|
@@ -319,7 +319,7 @@ class SinglyLinkedList {
|
|
|
319
319
|
const array = [];
|
|
320
320
|
let current = this.head;
|
|
321
321
|
while (current) {
|
|
322
|
-
array.push(current.
|
|
322
|
+
array.push(current.value);
|
|
323
323
|
current = current.next;
|
|
324
324
|
}
|
|
325
325
|
return array;
|
|
@@ -352,8 +352,8 @@ class SinglyLinkedList {
|
|
|
352
352
|
find(callback) {
|
|
353
353
|
let current = this.head;
|
|
354
354
|
while (current) {
|
|
355
|
-
if (callback(current.
|
|
356
|
-
return current.
|
|
355
|
+
if (callback(current.value)) {
|
|
356
|
+
return current.value;
|
|
357
357
|
}
|
|
358
358
|
current = current.next;
|
|
359
359
|
}
|
|
@@ -369,7 +369,7 @@ class SinglyLinkedList {
|
|
|
369
369
|
let index = 0;
|
|
370
370
|
let current = this.head;
|
|
371
371
|
while (current) {
|
|
372
|
-
if (current.
|
|
372
|
+
if (current.value === value) {
|
|
373
373
|
return index;
|
|
374
374
|
}
|
|
375
375
|
index++;
|
|
@@ -387,7 +387,7 @@ class SinglyLinkedList {
|
|
|
387
387
|
getNode(value) {
|
|
388
388
|
let current = this.head;
|
|
389
389
|
while (current) {
|
|
390
|
-
if (current.
|
|
390
|
+
if (current.value === value) {
|
|
391
391
|
return current;
|
|
392
392
|
}
|
|
393
393
|
current = current.next;
|
|
@@ -407,18 +407,18 @@ class SinglyLinkedList {
|
|
|
407
407
|
return false;
|
|
408
408
|
let existingValue;
|
|
409
409
|
if (existingValueOrNode instanceof SinglyLinkedListNode) {
|
|
410
|
-
existingValue = existingValueOrNode.
|
|
410
|
+
existingValue = existingValueOrNode.value;
|
|
411
411
|
}
|
|
412
412
|
else {
|
|
413
413
|
existingValue = existingValueOrNode;
|
|
414
414
|
}
|
|
415
|
-
if (this.head.
|
|
415
|
+
if (this.head.value === existingValue) {
|
|
416
416
|
this.unshift(newValue);
|
|
417
417
|
return true;
|
|
418
418
|
}
|
|
419
419
|
let current = this.head;
|
|
420
420
|
while (current.next) {
|
|
421
|
-
if (current.next.
|
|
421
|
+
if (current.next.value === existingValue) {
|
|
422
422
|
const newNode = new SinglyLinkedListNode(newValue);
|
|
423
423
|
newNode.next = current.next;
|
|
424
424
|
current.next = newNode;
|
|
@@ -466,7 +466,7 @@ class SinglyLinkedList {
|
|
|
466
466
|
let count = 0;
|
|
467
467
|
let current = this.head;
|
|
468
468
|
while (current) {
|
|
469
|
-
if (current.
|
|
469
|
+
if (current.value === value) {
|
|
470
470
|
count++;
|
|
471
471
|
}
|
|
472
472
|
current = current.next;
|
|
@@ -475,7 +475,7 @@ class SinglyLinkedList {
|
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
477
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
478
|
-
* @param callback - The callback parameter is a function that takes two arguments:
|
|
478
|
+
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
479
479
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
480
480
|
* current node in the linked list.
|
|
481
481
|
*/
|
|
@@ -483,7 +483,7 @@ class SinglyLinkedList {
|
|
|
483
483
|
let current = this.head;
|
|
484
484
|
let index = 0;
|
|
485
485
|
while (current) {
|
|
486
|
-
callback(current.
|
|
486
|
+
callback(current.value, index);
|
|
487
487
|
current = current.next;
|
|
488
488
|
index++;
|
|
489
489
|
}
|
|
@@ -500,7 +500,7 @@ class SinglyLinkedList {
|
|
|
500
500
|
const mappedList = new SinglyLinkedList();
|
|
501
501
|
let current = this.head;
|
|
502
502
|
while (current) {
|
|
503
|
-
mappedList.push(callback(current.
|
|
503
|
+
mappedList.push(callback(current.value));
|
|
504
504
|
current = current.next;
|
|
505
505
|
}
|
|
506
506
|
return mappedList;
|
|
@@ -516,8 +516,8 @@ class SinglyLinkedList {
|
|
|
516
516
|
const filteredList = new SinglyLinkedList();
|
|
517
517
|
let current = this.head;
|
|
518
518
|
while (current) {
|
|
519
|
-
if (callback(current.
|
|
520
|
-
filteredList.push(current.
|
|
519
|
+
if (callback(current.value)) {
|
|
520
|
+
filteredList.push(current.value);
|
|
521
521
|
}
|
|
522
522
|
current = current.next;
|
|
523
523
|
}
|
|
@@ -526,7 +526,7 @@ class SinglyLinkedList {
|
|
|
526
526
|
/**
|
|
527
527
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
528
528
|
* single value.
|
|
529
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `
|
|
529
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
530
530
|
* used to perform a specific operation on each element of the linked list.
|
|
531
531
|
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
532
532
|
* point for the reduction operation.
|
|
@@ -537,7 +537,7 @@ class SinglyLinkedList {
|
|
|
537
537
|
let accumulator = initialValue;
|
|
538
538
|
let current = this.head;
|
|
539
539
|
while (current) {
|
|
540
|
-
accumulator = callback(accumulator, current.
|
|
540
|
+
accumulator = callback(accumulator, current.value);
|
|
541
541
|
current = current.next;
|
|
542
542
|
}
|
|
543
543
|
return accumulator;
|
|
@@ -548,7 +548,7 @@ class SinglyLinkedList {
|
|
|
548
548
|
*[Symbol.iterator]() {
|
|
549
549
|
let current = this.head;
|
|
550
550
|
while (current) {
|
|
551
|
-
yield current.
|
|
551
|
+
yield current.value;
|
|
552
552
|
current = current.next;
|
|
553
553
|
}
|
|
554
554
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
6
|
import { SinglyLinkedList } from '../linked-list';
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class SkipQueue<E = any> extends SinglyLinkedList<E> {
|
|
8
8
|
/**
|
|
9
9
|
* The enqueue function adds a value to the end of an array.
|
|
10
10
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Queue = exports.
|
|
3
|
+
exports.Queue = exports.SkipQueue = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license MIT
|
|
6
6
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
7
7
|
* @class
|
|
8
8
|
*/
|
|
9
9
|
const linked_list_1 = require("../linked-list");
|
|
10
|
-
class
|
|
10
|
+
class SkipQueue extends linked_list_1.SinglyLinkedList {
|
|
11
11
|
/**
|
|
12
12
|
* The enqueue function adds a value to the end of an array.
|
|
13
13
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -27,10 +27,10 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
|
27
27
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
28
28
|
*/
|
|
29
29
|
peek() {
|
|
30
|
-
return this.head?.
|
|
30
|
+
return this.head?.value;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
exports.
|
|
33
|
+
exports.SkipQueue = SkipQueue;
|
|
34
34
|
class Queue {
|
|
35
35
|
/**
|
|
36
36
|
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BinaryTreeNode } from '../data-structures';
|
|
2
2
|
import { BinaryTreeDeletedResult, BTNKey, BinaryTreeNodeNested, BTNCallback } from '../types';
|
|
3
3
|
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
|
|
4
|
-
createNode(key: BTNKey,
|
|
5
|
-
add(keyOrNode: BTNKey | N | null,
|
|
4
|
+
createNode(key: BTNKey, value?: N['value']): N;
|
|
5
|
+
add(keyOrNode: BTNKey | N | null, value?: N['value']): N | null | undefined;
|
|
6
6
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VertexKey } from '../types';
|
|
2
|
-
export interface IGraph<V, E> {
|
|
3
|
-
createVertex(key: VertexKey,
|
|
4
|
-
createEdge(srcOrV1: VertexKey
|
|
2
|
+
export interface IGraph<V, E, VO, EO> {
|
|
3
|
+
createVertex(key: VertexKey, value?: V): VO;
|
|
4
|
+
createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
5
5
|
}
|