graph-typed 1.47.6 → 1.47.8
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 +40 -22
- package/dist/data-structures/binary-tree/avl-tree.js +45 -36
- package/dist/data-structures/binary-tree/binary-tree.d.ts +105 -113
- package/dist/data-structures/binary-tree/binary-tree.js +133 -119
- package/dist/data-structures/binary-tree/bst.d.ts +53 -44
- package/dist/data-structures/binary-tree/bst.js +137 -154
- package/dist/data-structures/binary-tree/rb-tree.d.ts +48 -15
- package/dist/data-structures/binary-tree/rb-tree.js +70 -33
- package/dist/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +26 -37
- package/dist/data-structures/binary-tree/tree-multimap.js +58 -137
- package/dist/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/data-structures/graph/abstract-graph.js +30 -30
- package/dist/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/data-structures/graph/directed-graph.js +28 -28
- package/dist/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/data-structures/graph/undirected-graph.js +18 -18
- package/dist/data-structures/hash/hash-map.d.ts +2 -6
- package/dist/data-structures/hash/hash-map.js +5 -8
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/data-structures/queue/queue.d.ts +13 -13
- package/dist/data-structures/queue/queue.js +13 -13
- package/dist/data-structures/stack/stack.d.ts +6 -6
- package/dist/data-structures/stack/stack.js +7 -7
- package/dist/data-structures/trie/trie.d.ts +3 -0
- package/dist/data-structures/trie/trie.js +19 -4
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/types/common.d.ts +6 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -2
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +59 -39
- package/src/data-structures/binary-tree/binary-tree.ts +192 -180
- package/src/data-structures/binary-tree/bst.ts +157 -154
- package/src/data-structures/binary-tree/rb-tree.ts +78 -37
- package/src/data-structures/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +67 -145
- package/src/data-structures/graph/abstract-graph.ts +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/data-structures/trie/trie.ts +23 -4
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +11 -1
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/src/types/data-structures/hash/hash-map.ts +1 -2
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class DoublyLinkedListNode<E = any> {
|
|
9
9
|
value: E;
|
|
10
|
-
next: DoublyLinkedListNode<E> |
|
|
11
|
-
prev: DoublyLinkedListNode<E> |
|
|
10
|
+
next: DoublyLinkedListNode<E> | undefined;
|
|
11
|
+
prev: DoublyLinkedListNode<E> | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
14
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
|
|
@@ -21,10 +21,10 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
21
21
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
22
22
|
*/
|
|
23
23
|
constructor(elements?: Iterable<E>);
|
|
24
|
-
protected _head: DoublyLinkedListNode<E> |
|
|
25
|
-
get head(): DoublyLinkedListNode<E> |
|
|
26
|
-
protected _tail: DoublyLinkedListNode<E> |
|
|
27
|
-
get tail(): DoublyLinkedListNode<E> |
|
|
24
|
+
protected _head: DoublyLinkedListNode<E> | undefined;
|
|
25
|
+
get head(): DoublyLinkedListNode<E> | undefined;
|
|
26
|
+
protected _tail: DoublyLinkedListNode<E> | undefined;
|
|
27
|
+
get tail(): DoublyLinkedListNode<E> | undefined;
|
|
28
28
|
protected _length: number;
|
|
29
29
|
get length(): number;
|
|
30
30
|
get size(): number;
|
|
@@ -76,7 +76,7 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
76
76
|
*
|
|
77
77
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
78
78
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
79
|
-
* list is empty, it returns
|
|
79
|
+
* list is empty, it returns undefined.
|
|
80
80
|
*/
|
|
81
81
|
pop(): E | undefined;
|
|
82
82
|
/**
|
|
@@ -89,7 +89,7 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
89
89
|
*
|
|
90
90
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
91
91
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
92
|
-
* list is empty, it returns
|
|
92
|
+
* list is empty, it returns undefined.
|
|
93
93
|
*/
|
|
94
94
|
popLast(): E | undefined;
|
|
95
95
|
/**
|
|
@@ -152,8 +152,8 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
152
152
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
153
153
|
* Space Complexity: O(1)
|
|
154
154
|
*
|
|
155
|
-
* The `getFirst` function returns the first node in a doubly linked list, or
|
|
156
|
-
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `
|
|
155
|
+
* The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
156
|
+
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
157
157
|
*/
|
|
158
158
|
getFirst(): E | undefined;
|
|
159
159
|
/**
|
|
@@ -164,8 +164,8 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
164
164
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
165
165
|
* Space Complexity: O(1)
|
|
166
166
|
*
|
|
167
|
-
* The `getLast` function returns the last node in a doubly linked list, or
|
|
168
|
-
* @returns The method `getLast()` returns the last node of the doubly linked list, or `
|
|
167
|
+
* The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
168
|
+
* @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
169
169
|
*/
|
|
170
170
|
getLast(): E | undefined;
|
|
171
171
|
/**
|
|
@@ -176,11 +176,11 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
176
176
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
177
177
|
* Space Complexity: O(1)
|
|
178
178
|
*
|
|
179
|
-
* The `getAt` function returns the value at a specified index in a linked list, or
|
|
179
|
+
* The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
180
180
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
181
181
|
* retrieve from the list.
|
|
182
182
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
183
|
-
* or the linked list is empty, it will return
|
|
183
|
+
* or the linked list is empty, it will return undefined.
|
|
184
184
|
*/
|
|
185
185
|
getAt(index: number): E | undefined;
|
|
186
186
|
/**
|
|
@@ -191,14 +191,14 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
191
191
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
192
192
|
* Space Complexity: O(1)
|
|
193
193
|
*
|
|
194
|
-
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or
|
|
194
|
+
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
195
195
|
* range.
|
|
196
196
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
197
197
|
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
198
198
|
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
199
|
-
* valid range of the linked list, otherwise it returns `
|
|
199
|
+
* valid range of the linked list, otherwise it returns `undefined`.
|
|
200
200
|
*/
|
|
201
|
-
getNodeAt(index: number): DoublyLinkedListNode<E> |
|
|
201
|
+
getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
|
|
202
202
|
/**
|
|
203
203
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
204
204
|
* Space Complexity: O(1)
|
|
@@ -208,12 +208,12 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
208
208
|
* Space Complexity: O(1)
|
|
209
209
|
*
|
|
210
210
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
211
|
-
* node if found, otherwise it returns
|
|
211
|
+
* node if found, otherwise it returns undefined.
|
|
212
212
|
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
213
213
|
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
|
|
214
|
-
* is found in the linked list. If no such node is found, it returns `
|
|
214
|
+
* is found in the linked list. If no such node is found, it returns `undefined`.
|
|
215
215
|
*/
|
|
216
|
-
getNode(value: E |
|
|
216
|
+
getNode(value: E | undefined): DoublyLinkedListNode<E> | undefined;
|
|
217
217
|
/**
|
|
218
218
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
219
219
|
* Space Complexity: O(1)
|
|
@@ -277,7 +277,7 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
277
277
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
278
278
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
279
279
|
* data structure. It is of type number.
|
|
280
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `
|
|
280
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
281
281
|
* bounds.
|
|
282
282
|
*/
|
|
283
283
|
deleteAt(index: number): E | undefined;
|
|
@@ -295,14 +295,14 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
295
295
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
|
|
296
296
|
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
|
|
297
297
|
*/
|
|
298
|
-
delete(valOrNode: E | DoublyLinkedListNode<E> |
|
|
298
|
+
delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
299
299
|
/**
|
|
300
300
|
* The function checks if a variable has a length greater than zero and returns a boolean value.
|
|
301
301
|
* @returns A boolean value is being returned.
|
|
302
302
|
*/
|
|
303
303
|
isEmpty(): boolean;
|
|
304
304
|
/**
|
|
305
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to
|
|
305
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
306
306
|
*/
|
|
307
307
|
clear(): void;
|
|
308
308
|
/**
|
|
@@ -317,9 +317,9 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
317
317
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
318
318
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
319
319
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
320
|
-
* the callback function. If no element satisfies the condition, it returns `
|
|
320
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
321
321
|
*/
|
|
322
|
-
find(callback: (value: E) => boolean): E |
|
|
322
|
+
find(callback: (value: E) => boolean): E | undefined;
|
|
323
323
|
/**
|
|
324
324
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
325
325
|
* Space Complexity: O(1)
|
|
@@ -344,13 +344,13 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
344
344
|
* Space Complexity: O(1)
|
|
345
345
|
*
|
|
346
346
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
347
|
-
* value that satisfies the given callback function, or
|
|
347
|
+
* value that satisfies the given callback function, or undefined if no value satisfies the callback.
|
|
348
348
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
349
349
|
* function is used to determine whether a given value satisfies a certain condition.
|
|
350
350
|
* @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
|
|
351
|
-
* the callback function. If no value satisfies the condition, it returns `
|
|
351
|
+
* the callback function. If no value satisfies the condition, it returns `undefined`.
|
|
352
352
|
*/
|
|
353
|
-
findBackward(callback: (value: E) => boolean): E |
|
|
353
|
+
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
354
354
|
/**
|
|
355
355
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
356
356
|
* Space Complexity: O(1)
|
|
@@ -16,8 +16,8 @@ class DoublyLinkedListNode {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(value) {
|
|
18
18
|
this.value = value;
|
|
19
|
-
this.next =
|
|
20
|
-
this.prev =
|
|
19
|
+
this.next = undefined;
|
|
20
|
+
this.prev = undefined;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.DoublyLinkedListNode = DoublyLinkedListNode;
|
|
@@ -26,8 +26,8 @@ class DoublyLinkedList {
|
|
|
26
26
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
27
27
|
*/
|
|
28
28
|
constructor(elements) {
|
|
29
|
-
this._head =
|
|
30
|
-
this._tail =
|
|
29
|
+
this._head = undefined;
|
|
30
|
+
this._tail = undefined;
|
|
31
31
|
this._length = 0;
|
|
32
32
|
if (elements) {
|
|
33
33
|
for (const el of elements) {
|
|
@@ -115,19 +115,19 @@ class DoublyLinkedList {
|
|
|
115
115
|
*
|
|
116
116
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
117
117
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
118
|
-
* list is empty, it returns
|
|
118
|
+
* list is empty, it returns undefined.
|
|
119
119
|
*/
|
|
120
120
|
pop() {
|
|
121
121
|
if (!this.tail)
|
|
122
122
|
return undefined;
|
|
123
123
|
const removedNode = this.tail;
|
|
124
124
|
if (this.head === this.tail) {
|
|
125
|
-
this._head =
|
|
126
|
-
this._tail =
|
|
125
|
+
this._head = undefined;
|
|
126
|
+
this._tail = undefined;
|
|
127
127
|
}
|
|
128
128
|
else {
|
|
129
129
|
this._tail = removedNode.prev;
|
|
130
|
-
this.tail.next =
|
|
130
|
+
this.tail.next = undefined;
|
|
131
131
|
}
|
|
132
132
|
this._length--;
|
|
133
133
|
return removedNode.value;
|
|
@@ -142,7 +142,7 @@ class DoublyLinkedList {
|
|
|
142
142
|
*
|
|
143
143
|
* The `popLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
144
144
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
145
|
-
* list is empty, it returns
|
|
145
|
+
* list is empty, it returns undefined.
|
|
146
146
|
*/
|
|
147
147
|
popLast() {
|
|
148
148
|
return this.pop();
|
|
@@ -164,12 +164,12 @@ class DoublyLinkedList {
|
|
|
164
164
|
return undefined;
|
|
165
165
|
const removedNode = this.head;
|
|
166
166
|
if (this.head === this.tail) {
|
|
167
|
-
this._head =
|
|
168
|
-
this._tail =
|
|
167
|
+
this._head = undefined;
|
|
168
|
+
this._tail = undefined;
|
|
169
169
|
}
|
|
170
170
|
else {
|
|
171
171
|
this._head = removedNode.next;
|
|
172
|
-
this.head.prev =
|
|
172
|
+
this.head.prev = undefined;
|
|
173
173
|
}
|
|
174
174
|
this._length--;
|
|
175
175
|
return removedNode.value;
|
|
@@ -237,8 +237,8 @@ class DoublyLinkedList {
|
|
|
237
237
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
238
238
|
* Space Complexity: O(1)
|
|
239
239
|
*
|
|
240
|
-
* The `getFirst` function returns the first node in a doubly linked list, or
|
|
241
|
-
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `
|
|
240
|
+
* The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
241
|
+
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
242
242
|
*/
|
|
243
243
|
getFirst() {
|
|
244
244
|
var _a;
|
|
@@ -252,8 +252,8 @@ class DoublyLinkedList {
|
|
|
252
252
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
253
253
|
* Space Complexity: O(1)
|
|
254
254
|
*
|
|
255
|
-
* The `getLast` function returns the last node in a doubly linked list, or
|
|
256
|
-
* @returns The method `getLast()` returns the last node of the doubly linked list, or `
|
|
255
|
+
* The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
256
|
+
* @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
257
257
|
*/
|
|
258
258
|
getLast() {
|
|
259
259
|
var _a;
|
|
@@ -267,11 +267,11 @@ class DoublyLinkedList {
|
|
|
267
267
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
268
268
|
* Space Complexity: O(1)
|
|
269
269
|
*
|
|
270
|
-
* The `getAt` function returns the value at a specified index in a linked list, or
|
|
270
|
+
* The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
271
271
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
272
272
|
* retrieve from the list.
|
|
273
273
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
274
|
-
* or the linked list is empty, it will return
|
|
274
|
+
* or the linked list is empty, it will return undefined.
|
|
275
275
|
*/
|
|
276
276
|
getAt(index) {
|
|
277
277
|
if (index < 0 || index >= this.length)
|
|
@@ -290,16 +290,16 @@ class DoublyLinkedList {
|
|
|
290
290
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
291
291
|
* Space Complexity: O(1)
|
|
292
292
|
*
|
|
293
|
-
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or
|
|
293
|
+
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
294
294
|
* range.
|
|
295
295
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
296
296
|
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
297
297
|
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
298
|
-
* valid range of the linked list, otherwise it returns `
|
|
298
|
+
* valid range of the linked list, otherwise it returns `undefined`.
|
|
299
299
|
*/
|
|
300
300
|
getNodeAt(index) {
|
|
301
301
|
if (index < 0 || index >= this.length)
|
|
302
|
-
return
|
|
302
|
+
return undefined;
|
|
303
303
|
let current = this.head;
|
|
304
304
|
for (let i = 0; i < index; i++) {
|
|
305
305
|
current = current.next;
|
|
@@ -315,10 +315,10 @@ class DoublyLinkedList {
|
|
|
315
315
|
* Space Complexity: O(1)
|
|
316
316
|
*
|
|
317
317
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
318
|
-
* node if found, otherwise it returns
|
|
318
|
+
* node if found, otherwise it returns undefined.
|
|
319
319
|
* @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
|
|
320
320
|
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
|
|
321
|
-
* is found in the linked list. If no such node is found, it returns `
|
|
321
|
+
* is found in the linked list. If no such node is found, it returns `undefined`.
|
|
322
322
|
*/
|
|
323
323
|
getNode(value) {
|
|
324
324
|
let current = this.head;
|
|
@@ -328,7 +328,7 @@ class DoublyLinkedList {
|
|
|
328
328
|
}
|
|
329
329
|
current = current.next;
|
|
330
330
|
}
|
|
331
|
-
return
|
|
331
|
+
return undefined;
|
|
332
332
|
}
|
|
333
333
|
/**
|
|
334
334
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -459,7 +459,7 @@ class DoublyLinkedList {
|
|
|
459
459
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
460
460
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
461
461
|
* data structure. It is of type number.
|
|
462
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `
|
|
462
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
463
463
|
* bounds.
|
|
464
464
|
*/
|
|
465
465
|
deleteAt(index) {
|
|
@@ -525,11 +525,11 @@ class DoublyLinkedList {
|
|
|
525
525
|
return this.length === 0;
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
528
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to
|
|
528
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
529
529
|
*/
|
|
530
530
|
clear() {
|
|
531
|
-
this._head =
|
|
532
|
-
this._tail =
|
|
531
|
+
this._head = undefined;
|
|
532
|
+
this._tail = undefined;
|
|
533
533
|
this._length = 0;
|
|
534
534
|
}
|
|
535
535
|
/**
|
|
@@ -544,7 +544,7 @@ class DoublyLinkedList {
|
|
|
544
544
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
545
545
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
546
546
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
547
|
-
* the callback function. If no element satisfies the condition, it returns `
|
|
547
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
548
548
|
*/
|
|
549
549
|
find(callback) {
|
|
550
550
|
let current = this.head;
|
|
@@ -554,7 +554,7 @@ class DoublyLinkedList {
|
|
|
554
554
|
}
|
|
555
555
|
current = current.next;
|
|
556
556
|
}
|
|
557
|
-
return
|
|
557
|
+
return undefined;
|
|
558
558
|
}
|
|
559
559
|
/**
|
|
560
560
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -591,11 +591,11 @@ class DoublyLinkedList {
|
|
|
591
591
|
* Space Complexity: O(1)
|
|
592
592
|
*
|
|
593
593
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
594
|
-
* value that satisfies the given callback function, or
|
|
594
|
+
* value that satisfies the given callback function, or undefined if no value satisfies the callback.
|
|
595
595
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
596
596
|
* function is used to determine whether a given value satisfies a certain condition.
|
|
597
597
|
* @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
|
|
598
|
-
* the callback function. If no value satisfies the condition, it returns `
|
|
598
|
+
* the callback function. If no value satisfies the condition, it returns `undefined`.
|
|
599
599
|
*/
|
|
600
600
|
findBackward(callback) {
|
|
601
601
|
let current = this.tail;
|
|
@@ -605,7 +605,7 @@ class DoublyLinkedList {
|
|
|
605
605
|
}
|
|
606
606
|
current = current.prev;
|
|
607
607
|
}
|
|
608
|
-
return
|
|
608
|
+
return undefined;
|
|
609
609
|
}
|
|
610
610
|
/**
|
|
611
611
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class SinglyLinkedListNode<E = any> {
|
|
9
9
|
value: E;
|
|
10
|
-
next: SinglyLinkedListNode<E> |
|
|
10
|
+
next: SinglyLinkedListNode<E> | undefined;
|
|
11
11
|
/**
|
|
12
|
-
* The constructor function initializes an instance of a class with a given value and sets the next property to
|
|
12
|
+
* The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
|
|
13
13
|
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
14
14
|
* will be stored in the node of a linked list.
|
|
15
15
|
*/
|
|
@@ -20,10 +20,10 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
20
20
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
21
21
|
*/
|
|
22
22
|
constructor(elements?: Iterable<E>);
|
|
23
|
-
protected _head: SinglyLinkedListNode<E> |
|
|
24
|
-
get head(): SinglyLinkedListNode<E> |
|
|
25
|
-
protected _tail: SinglyLinkedListNode<E> |
|
|
26
|
-
get tail(): SinglyLinkedListNode<E> |
|
|
23
|
+
protected _head: SinglyLinkedListNode<E> | undefined;
|
|
24
|
+
get head(): SinglyLinkedListNode<E> | undefined;
|
|
25
|
+
protected _tail: SinglyLinkedListNode<E> | undefined;
|
|
26
|
+
get tail(): SinglyLinkedListNode<E> | undefined;
|
|
27
27
|
protected _length: number;
|
|
28
28
|
get length(): number;
|
|
29
29
|
/**
|
|
@@ -77,7 +77,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
77
77
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
78
78
|
* pointers accordingly.
|
|
79
79
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
80
|
-
* the linked list is empty, it returns `
|
|
80
|
+
* the linked list is empty, it returns `undefined`.
|
|
81
81
|
*/
|
|
82
82
|
pop(): E | undefined;
|
|
83
83
|
/**
|
|
@@ -91,7 +91,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
91
91
|
* The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
92
92
|
* pointers accordingly.
|
|
93
93
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
94
|
-
* the linked list is empty, it returns `
|
|
94
|
+
* the linked list is empty, it returns `undefined`.
|
|
95
95
|
*/
|
|
96
96
|
popLast(): E | undefined;
|
|
97
97
|
/**
|
|
@@ -152,11 +152,11 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
152
152
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
153
153
|
* Space Complexity: O(1) - Constant space.
|
|
154
154
|
*
|
|
155
|
-
* The function `getAt` returns the value at a specified index in a linked list, or
|
|
155
|
+
* The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
|
|
156
156
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
157
157
|
* retrieve from the list.
|
|
158
|
-
* @returns The method `getAt(index: number): E |
|
|
159
|
-
* `
|
|
158
|
+
* @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
|
|
159
|
+
* `undefined` if the index is out of bounds.
|
|
160
160
|
*/
|
|
161
161
|
getAt(index: number): E | undefined;
|
|
162
162
|
/**
|
|
@@ -171,9 +171,9 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
171
171
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
172
172
|
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
173
173
|
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
|
|
174
|
-
* specified index exists, or `
|
|
174
|
+
* specified index exists, or `undefined` if the index is out of bounds.
|
|
175
175
|
*/
|
|
176
|
-
getNodeAt(index: number): SinglyLinkedListNode<E> |
|
|
176
|
+
getNodeAt(index: number): SinglyLinkedListNode<E> | undefined;
|
|
177
177
|
/**
|
|
178
178
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
179
179
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -185,7 +185,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
185
185
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
186
186
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
187
187
|
* data structure. It is of type number.
|
|
188
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `
|
|
188
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
189
189
|
* bounds.
|
|
190
190
|
*/
|
|
191
191
|
deleteAt(index: number): E | undefined;
|
|
@@ -203,7 +203,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
203
203
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
|
|
204
204
|
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
205
205
|
*/
|
|
206
|
-
delete(valueOrNode: E | SinglyLinkedListNode<E> |
|
|
206
|
+
delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined | undefined): boolean;
|
|
207
207
|
/**
|
|
208
208
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
209
209
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -228,7 +228,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
228
228
|
*/
|
|
229
229
|
isEmpty(): boolean;
|
|
230
230
|
/**
|
|
231
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to
|
|
231
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
232
232
|
*/
|
|
233
233
|
clear(): void;
|
|
234
234
|
/**
|
|
@@ -267,9 +267,9 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
267
267
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
268
268
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
269
269
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
270
|
-
* the callback function. If no element satisfies the condition, it returns `
|
|
270
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
271
271
|
*/
|
|
272
|
-
find(callback: (value: E) => boolean): E |
|
|
272
|
+
find(callback: (value: E) => boolean): E | undefined;
|
|
273
273
|
/**
|
|
274
274
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
275
275
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -293,12 +293,12 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
293
293
|
* Space Complexity: O(1) - Constant space.
|
|
294
294
|
*
|
|
295
295
|
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
|
|
296
|
-
*
|
|
296
|
+
* undefined.
|
|
297
297
|
* @param {E} value - The value parameter is the value that we want to search for in the linked list.
|
|
298
298
|
* @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
|
|
299
|
-
* the specified value is found, the function returns `
|
|
299
|
+
* the specified value is found, the function returns `undefined`.
|
|
300
300
|
*/
|
|
301
|
-
getNode(value: E): SinglyLinkedListNode<E> |
|
|
301
|
+
getNode(value: E): SinglyLinkedListNode<E> | undefined;
|
|
302
302
|
/**
|
|
303
303
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
304
304
|
* Space Complexity: O(1) - Constant space.
|