data-structure-typed 1.39.5 → 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 +2 -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 +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +24 -24
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +12 -12
- package/dist/cjs/data-structures/graph/directed-graph.js +15 -15
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +9 -9
- package/dist/cjs/data-structures/graph/map-graph.js +13 -13
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +11 -11
- package/dist/cjs/data-structures/graph/undirected-graph.js +14 -14
- 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.js +1 -1
- 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 +2 -2
- 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 +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +26 -26
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +12 -12
- package/dist/mjs/data-structures/graph/directed-graph.js +15 -15
- package/dist/mjs/data-structures/graph/map-graph.d.ts +9 -9
- package/dist/mjs/data-structures/graph/map-graph.js +13 -13
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +11 -11
- package/dist/mjs/data-structures/graph/undirected-graph.js +14 -14
- 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.js +1 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/interfaces/graph.d.ts +2 -2
- 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 +34 -34
- package/src/data-structures/graph/directed-graph.ts +16 -16
- package/src/data-structures/graph/map-graph.ts +13 -13
- package/src/data-structures/graph/undirected-graph.ts +15 -15
- 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 +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +2 -2
- 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 +22 -12
- package/test/unit/data-structures/graph/undirected-graph.test.ts +8 -0
- 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/utils/big-o.ts +7 -7
|
@@ -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
|
*/
|
|
@@ -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
|
}
|
|
@@ -27,7 +27,7 @@ class SkipQueue 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
33
|
exports.SkipQueue = SkipQueue;
|
|
@@ -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
2
|
export interface IGraph<V, E, VO, EO> {
|
|
3
|
-
createVertex(key: VertexKey,
|
|
4
|
-
createEdge(srcOrV1: VertexKey
|
|
3
|
+
createVertex(key: VertexKey, value?: V): VO;
|
|
4
|
+
createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
5
5
|
}
|