min-heap-typed 1.50.1 → 1.50.2
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/base/iterable-base.d.ts +114 -9
- package/dist/data-structures/base/iterable-base.js +143 -7
- package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
- package/dist/data-structures/binary-tree/avl-tree.js +68 -71
- package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/data-structures/binary-tree/bst.d.ts +54 -74
- package/dist/data-structures/binary-tree/bst.js +30 -71
- package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
- package/dist/data-structures/binary-tree/rb-tree.js +84 -89
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
- package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/data-structures/graph/abstract-graph.js +3 -0
- package/dist/data-structures/graph/directed-graph.d.ts +14 -0
- package/dist/data-structures/graph/directed-graph.js +26 -0
- package/dist/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/data-structures/graph/map-graph.js +14 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
- package/dist/data-structures/graph/undirected-graph.js +25 -0
- package/dist/data-structures/hash/hash-map.d.ts +121 -15
- package/dist/data-structures/hash/hash-map.js +160 -25
- package/dist/data-structures/heap/heap.d.ts +66 -6
- package/dist/data-structures/heap/heap.js +66 -6
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
- package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
- package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/data-structures/matrix/matrix.js +50 -11
- package/dist/data-structures/queue/deque.d.ts +49 -19
- package/dist/data-structures/queue/deque.js +101 -47
- package/dist/data-structures/queue/queue.d.ts +39 -5
- package/dist/data-structures/queue/queue.js +47 -5
- package/dist/data-structures/stack/stack.d.ts +16 -0
- package/dist/data-structures/stack/stack.js +22 -0
- package/dist/data-structures/trie/trie.d.ts +38 -1
- package/dist/data-structures/trie/trie.js +41 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +172 -19
- package/src/data-structures/binary-tree/avl-tree.ts +97 -97
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +89 -131
- package/src/data-structures/binary-tree/rb-tree.ts +127 -155
- package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +28 -0
- package/src/data-structures/hash/hash-map.ts +175 -34
- package/src/data-structures/heap/heap.ts +66 -6
- package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
- package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/queue/deque.ts +108 -49
- package/src/data-structures/queue/queue.ts +51 -5
- package/src/data-structures/stack/stack.ts +24 -0
- package/src/data-structures/trie/trie.ts +45 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
|
@@ -21,6 +21,16 @@ const base_1 = require("../base");
|
|
|
21
21
|
* 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
|
|
22
22
|
*/
|
|
23
23
|
class Heap extends base_1.IterableElementBase {
|
|
24
|
+
/**
|
|
25
|
+
* The constructor initializes a heap data structure with optional elements and options.
|
|
26
|
+
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
27
|
+
* elements to be added to the heap. It is an optional parameter and if not provided, the heap will
|
|
28
|
+
* be initialized as empty.
|
|
29
|
+
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
30
|
+
* configuration options for the heap. In this case, it is used to specify a custom comparator
|
|
31
|
+
* function for comparing elements in the heap. The comparator function is used to determine the
|
|
32
|
+
* order of elements in the heap.
|
|
33
|
+
*/
|
|
24
34
|
constructor(elements = [], options) {
|
|
25
35
|
super();
|
|
26
36
|
this._comparator = (a, b) => {
|
|
@@ -44,9 +54,17 @@ class Heap extends base_1.IterableElementBase {
|
|
|
44
54
|
// this.fix();
|
|
45
55
|
}
|
|
46
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The function returns the value of the _comparator property.
|
|
59
|
+
* @returns The `_comparator` property is being returned.
|
|
60
|
+
*/
|
|
47
61
|
get comparator() {
|
|
48
62
|
return this._comparator;
|
|
49
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The function returns an array of elements.
|
|
66
|
+
* @returns The elements array is being returned.
|
|
67
|
+
*/
|
|
50
68
|
get elements() {
|
|
51
69
|
return this._elements;
|
|
52
70
|
}
|
|
@@ -74,11 +92,12 @@ class Heap extends base_1.IterableElementBase {
|
|
|
74
92
|
return new Heap(elements, options);
|
|
75
93
|
}
|
|
76
94
|
/**
|
|
77
|
-
* Time Complexity: O(log n)
|
|
95
|
+
* Time Complexity: O(log n)
|
|
78
96
|
* Space Complexity: O(1)
|
|
97
|
+
* where n is the number of elements in the heap.
|
|
79
98
|
*/
|
|
80
99
|
/**
|
|
81
|
-
* Time Complexity: O(log n)
|
|
100
|
+
* Time Complexity: O(log n)
|
|
82
101
|
* Space Complexity: O(1)
|
|
83
102
|
*
|
|
84
103
|
* Insert an element into the heap and maintain the heap properties.
|
|
@@ -89,11 +108,12 @@ class Heap extends base_1.IterableElementBase {
|
|
|
89
108
|
return this._bubbleUp(this.elements.length - 1);
|
|
90
109
|
}
|
|
91
110
|
/**
|
|
92
|
-
* Time Complexity: O(log n)
|
|
111
|
+
* Time Complexity: O(log n)
|
|
93
112
|
* Space Complexity: O(1)
|
|
113
|
+
* where n is the number of elements in the heap.
|
|
94
114
|
*/
|
|
95
115
|
/**
|
|
96
|
-
* Time Complexity: O(log n)
|
|
116
|
+
* Time Complexity: O(log n)
|
|
97
117
|
* Space Complexity: O(1)
|
|
98
118
|
*
|
|
99
119
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -111,6 +131,9 @@ class Heap extends base_1.IterableElementBase {
|
|
|
111
131
|
return value;
|
|
112
132
|
}
|
|
113
133
|
/**
|
|
134
|
+
* Time Complexity: O(1)
|
|
135
|
+
* Space Complexity: O(1)
|
|
136
|
+
*
|
|
114
137
|
* Peek at the top element of the heap without removing it.
|
|
115
138
|
* @returns The top element or undefined if the heap is empty.
|
|
116
139
|
*/
|
|
@@ -361,6 +384,9 @@ class Heap extends base_1.IterableElementBase {
|
|
|
361
384
|
}
|
|
362
385
|
return mappedHeap;
|
|
363
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* The function `_getIterator` returns an iterable iterator for the elements in the class.
|
|
389
|
+
*/
|
|
364
390
|
*_getIterator() {
|
|
365
391
|
for (const element of this.elements) {
|
|
366
392
|
yield element;
|
|
@@ -419,6 +445,16 @@ class Heap extends base_1.IterableElementBase {
|
|
|
419
445
|
}
|
|
420
446
|
exports.Heap = Heap;
|
|
421
447
|
class FibonacciHeapNode {
|
|
448
|
+
/**
|
|
449
|
+
* The constructor function initializes an object with an element and a degree, and sets the marked
|
|
450
|
+
* property to false.
|
|
451
|
+
* @param {E} element - The "element" parameter represents the value or data that will be stored in
|
|
452
|
+
* the node of a data structure. It can be any type of data, such as a number, string, object, or
|
|
453
|
+
* even another data structure.
|
|
454
|
+
* @param [degree=0] - The degree parameter represents the degree of the element in a data structure
|
|
455
|
+
* called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
|
|
456
|
+
* degree is set to 0 when a new node is created.
|
|
457
|
+
*/
|
|
422
458
|
constructor(element, degree = 0) {
|
|
423
459
|
this.element = element;
|
|
424
460
|
this.degree = degree;
|
|
@@ -427,6 +463,13 @@ class FibonacciHeapNode {
|
|
|
427
463
|
}
|
|
428
464
|
exports.FibonacciHeapNode = FibonacciHeapNode;
|
|
429
465
|
class FibonacciHeap {
|
|
466
|
+
/**
|
|
467
|
+
* The constructor function initializes a FibonacciHeap object with an optional comparator function.
|
|
468
|
+
* @param [comparator] - The `comparator` parameter is an optional argument that represents a
|
|
469
|
+
* function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
|
|
470
|
+
* will be used to determine the order of elements in the heap. If no comparator function is
|
|
471
|
+
* provided, a default comparator function will be used.
|
|
472
|
+
*/
|
|
430
473
|
constructor(comparator) {
|
|
431
474
|
this._size = 0;
|
|
432
475
|
this.clear();
|
|
@@ -435,15 +478,32 @@ class FibonacciHeap {
|
|
|
435
478
|
throw new Error('FibonacciHeap constructor: given comparator should be a function.');
|
|
436
479
|
}
|
|
437
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* The function returns the root node of a Fibonacci heap.
|
|
483
|
+
* @returns The method is returning either a FibonacciHeapNode object or undefined.
|
|
484
|
+
*/
|
|
438
485
|
get root() {
|
|
439
486
|
return this._root;
|
|
440
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* The function returns the size of an object.
|
|
490
|
+
* @returns The size of the object, which is a number.
|
|
491
|
+
*/
|
|
441
492
|
get size() {
|
|
442
493
|
return this._size;
|
|
443
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* The function returns the minimum node in a Fibonacci heap.
|
|
497
|
+
* @returns The method is returning the minimum node of the Fibonacci heap, which is of type
|
|
498
|
+
* `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
|
|
499
|
+
*/
|
|
444
500
|
get min() {
|
|
445
501
|
return this._min;
|
|
446
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* The function returns the comparator used for comparing elements.
|
|
505
|
+
* @returns The `_comparator` property of the object.
|
|
506
|
+
*/
|
|
447
507
|
get comparator() {
|
|
448
508
|
return this._comparator;
|
|
449
509
|
}
|
|
@@ -726,11 +786,11 @@ class FibonacciHeap {
|
|
|
726
786
|
y.parent = x;
|
|
727
787
|
}
|
|
728
788
|
/**
|
|
729
|
-
* Time Complexity: O(n log n)
|
|
789
|
+
* Time Complexity: O(n log n)
|
|
730
790
|
* Space Complexity: O(n)
|
|
731
791
|
*/
|
|
732
792
|
/**
|
|
733
|
-
* Time Complexity: O(n log n)
|
|
793
|
+
* Time Complexity: O(n log n)
|
|
734
794
|
* Space Complexity: O(n)
|
|
735
795
|
*
|
|
736
796
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -26,21 +26,38 @@ export declare class DoublyLinkedListNode<E = any> {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
28
28
|
/**
|
|
29
|
-
* The constructor initializes
|
|
29
|
+
* The constructor initializes a linked list with optional elements.
|
|
30
|
+
* @param elements - The `elements` parameter is an optional iterable object that contains the
|
|
31
|
+
* initial elements to be added to the data structure. It defaults to an empty array if no elements
|
|
32
|
+
* are provided.
|
|
30
33
|
*/
|
|
31
34
|
constructor(elements?: Iterable<E>);
|
|
32
35
|
protected _head: DoublyLinkedListNode<E> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The `head` function returns the first node of a doubly linked list.
|
|
38
|
+
* @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
|
|
39
|
+
*/
|
|
33
40
|
get head(): DoublyLinkedListNode<E> | undefined;
|
|
34
41
|
protected _tail: DoublyLinkedListNode<E> | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The `tail` function returns the last node of a doubly linked list.
|
|
44
|
+
* @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
|
|
45
|
+
* `undefined`.
|
|
46
|
+
*/
|
|
35
47
|
get tail(): DoublyLinkedListNode<E> | undefined;
|
|
36
48
|
protected _size: number;
|
|
49
|
+
/**
|
|
50
|
+
* The function returns the size of an object.
|
|
51
|
+
* @returns The size of the object, which is a number.
|
|
52
|
+
*/
|
|
37
53
|
get size(): number;
|
|
38
54
|
/**
|
|
39
|
-
* Time Complexity: O(n)
|
|
55
|
+
* Time Complexity: O(n)
|
|
40
56
|
* Space Complexity: O(n)
|
|
57
|
+
* where n is the number of elements in the linked list.
|
|
41
58
|
*/
|
|
42
59
|
/**
|
|
43
|
-
* Time Complexity: O(n)
|
|
60
|
+
* Time Complexity: O(n)
|
|
44
61
|
* Space Complexity: O(1)
|
|
45
62
|
*
|
|
46
63
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -52,7 +69,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
52
69
|
* Space Complexity: O(1)
|
|
53
70
|
*/
|
|
54
71
|
/**
|
|
55
|
-
* Time Complexity: O(n)
|
|
72
|
+
* Time Complexity: O(n)
|
|
56
73
|
* Space Complexity: O(1)
|
|
57
74
|
*
|
|
58
75
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -99,7 +116,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
99
116
|
*/
|
|
100
117
|
pop(): E | undefined;
|
|
101
118
|
/**
|
|
102
|
-
* Time Complexity: O(n)
|
|
119
|
+
* Time Complexity: O(n)
|
|
103
120
|
* Space Complexity: O(1)
|
|
104
121
|
*/
|
|
105
122
|
/**
|
|
@@ -112,7 +129,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
112
129
|
*/
|
|
113
130
|
shift(): E | undefined;
|
|
114
131
|
/**
|
|
115
|
-
* Time Complexity: O(n)
|
|
132
|
+
* Time Complexity: O(n)
|
|
116
133
|
* Space Complexity: O(1)
|
|
117
134
|
*/
|
|
118
135
|
/**
|
|
@@ -125,26 +142,26 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
125
142
|
*/
|
|
126
143
|
unshift(value: E): boolean;
|
|
127
144
|
/**
|
|
128
|
-
* Time Complexity: O(n)
|
|
145
|
+
* Time Complexity: O(n)
|
|
129
146
|
* Space Complexity: O(1)
|
|
130
147
|
*/
|
|
131
148
|
/**
|
|
132
|
-
* Time Complexity: O(n)
|
|
149
|
+
* Time Complexity: O(n)
|
|
133
150
|
* Space Complexity: O(1)
|
|
134
151
|
*
|
|
135
|
-
* The `
|
|
152
|
+
* The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
136
153
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
137
154
|
* retrieve from the list.
|
|
138
155
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
139
156
|
* or the linked list is empty, it will return undefined.
|
|
140
157
|
*/
|
|
141
|
-
|
|
158
|
+
at(index: number): E | undefined;
|
|
142
159
|
/**
|
|
143
|
-
* Time Complexity: O(n)
|
|
160
|
+
* Time Complexity: O(n)
|
|
144
161
|
* Space Complexity: O(1)
|
|
145
162
|
*/
|
|
146
163
|
/**
|
|
147
|
-
* Time Complexity: O(n)
|
|
164
|
+
* Time Complexity: O(n)
|
|
148
165
|
* Space Complexity: O(1)
|
|
149
166
|
*
|
|
150
167
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
@@ -156,11 +173,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
156
173
|
*/
|
|
157
174
|
getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
|
|
158
175
|
/**
|
|
159
|
-
* Time Complexity: O(n)
|
|
176
|
+
* Time Complexity: O(n)
|
|
160
177
|
* Space Complexity: O(1)
|
|
161
178
|
*/
|
|
162
179
|
/**
|
|
163
|
-
* Time Complexity: O(n)
|
|
180
|
+
* Time Complexity: O(n)
|
|
164
181
|
* Space Complexity: O(1)
|
|
165
182
|
*
|
|
166
183
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
@@ -171,11 +188,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
171
188
|
*/
|
|
172
189
|
getNode(value: E | undefined): DoublyLinkedListNode<E> | undefined;
|
|
173
190
|
/**
|
|
174
|
-
* Time Complexity: O(n)
|
|
191
|
+
* Time Complexity: O(n)
|
|
175
192
|
* Space Complexity: O(1)
|
|
176
193
|
*/
|
|
177
194
|
/**
|
|
178
|
-
* Time Complexity: O(n)
|
|
195
|
+
* Time Complexity: O(n)
|
|
179
196
|
* Space Complexity: O(1)
|
|
180
197
|
*
|
|
181
198
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
@@ -188,11 +205,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
188
205
|
*/
|
|
189
206
|
addAt(index: number, value: E): boolean;
|
|
190
207
|
/**
|
|
191
|
-
* Time Complexity: O(n)
|
|
208
|
+
* Time Complexity: O(n)
|
|
192
209
|
* Space Complexity: O(1)
|
|
210
|
+
* where n is the number of elements in the linked list.
|
|
193
211
|
*/
|
|
194
212
|
/**
|
|
195
|
-
* Time Complexity: O(n)
|
|
213
|
+
* Time Complexity: O(n)
|
|
196
214
|
* Space Complexity: O(1)
|
|
197
215
|
*
|
|
198
216
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -206,11 +224,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
206
224
|
*/
|
|
207
225
|
addBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
208
226
|
/**
|
|
209
|
-
* Time Complexity: O(n)
|
|
227
|
+
* Time Complexity: O(n)
|
|
210
228
|
* Space Complexity: O(1)
|
|
211
229
|
*/
|
|
212
230
|
/**
|
|
213
|
-
* Time Complexity: O(n)
|
|
231
|
+
* Time Complexity: O(n)
|
|
214
232
|
* Space Complexity: O(1)
|
|
215
233
|
*
|
|
216
234
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -223,7 +241,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
223
241
|
*/
|
|
224
242
|
addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
225
243
|
/**
|
|
226
|
-
* Time Complexity: O(n)
|
|
244
|
+
* Time Complexity: O(n)
|
|
227
245
|
* Space Complexity: O(1)
|
|
228
246
|
*
|
|
229
247
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
@@ -234,7 +252,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
234
252
|
*/
|
|
235
253
|
deleteAt(index: number): boolean;
|
|
236
254
|
/**
|
|
237
|
-
* Time Complexity: O(n)
|
|
255
|
+
* Time Complexity: O(n)
|
|
238
256
|
* Space Complexity: O(1)
|
|
239
257
|
*
|
|
240
258
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -245,7 +263,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
245
263
|
*/
|
|
246
264
|
delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
247
265
|
/**
|
|
248
|
-
* Time Complexity: O(
|
|
266
|
+
* Time Complexity: O(1)
|
|
249
267
|
* Space Complexity: O(1)
|
|
250
268
|
*/
|
|
251
269
|
/**
|
|
@@ -254,7 +272,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
254
272
|
*/
|
|
255
273
|
isEmpty(): boolean;
|
|
256
274
|
/**
|
|
257
|
-
* Time Complexity: O(
|
|
275
|
+
* Time Complexity: O(1)
|
|
258
276
|
* Space Complexity: O(1)
|
|
259
277
|
*/
|
|
260
278
|
/**
|
|
@@ -262,26 +280,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
262
280
|
*/
|
|
263
281
|
clear(): void;
|
|
264
282
|
/**
|
|
265
|
-
* Time Complexity: O(n)
|
|
266
|
-
* Space Complexity: O(1)
|
|
267
|
-
*/
|
|
268
|
-
/**
|
|
269
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
270
|
-
* Space Complexity: O(1)
|
|
271
|
-
*
|
|
272
|
-
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
273
|
-
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
274
|
-
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
275
|
-
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
276
|
-
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
277
|
-
*/
|
|
278
|
-
find(callback: (value: E) => boolean): E | undefined;
|
|
279
|
-
/**
|
|
280
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
283
|
+
* Time Complexity: O(n)
|
|
281
284
|
* Space Complexity: O(1)
|
|
282
285
|
*/
|
|
283
286
|
/**
|
|
284
|
-
* Time Complexity: O(n)
|
|
287
|
+
* Time Complexity: O(n)
|
|
285
288
|
* Space Complexity: O(1)
|
|
286
289
|
*
|
|
287
290
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
@@ -292,11 +295,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
292
295
|
*/
|
|
293
296
|
indexOf(value: E): number;
|
|
294
297
|
/**
|
|
295
|
-
* Time Complexity: O(n)
|
|
298
|
+
* Time Complexity: O(n)
|
|
296
299
|
* Space Complexity: O(n)
|
|
297
300
|
*/
|
|
298
301
|
/**
|
|
299
|
-
* Time Complexity: O(n)
|
|
302
|
+
* Time Complexity: O(n)
|
|
300
303
|
* Space Complexity: O(1)
|
|
301
304
|
*
|
|
302
305
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
@@ -308,11 +311,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
308
311
|
*/
|
|
309
312
|
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
310
313
|
/**
|
|
311
|
-
* Time Complexity: O(n)
|
|
314
|
+
* Time Complexity: O(n)
|
|
312
315
|
* Space Complexity: O(n)
|
|
313
316
|
*/
|
|
314
317
|
/**
|
|
315
|
-
* Time Complexity: O(n)
|
|
318
|
+
* Time Complexity: O(n)
|
|
316
319
|
* Space Complexity: O(1)
|
|
317
320
|
*
|
|
318
321
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
@@ -323,7 +326,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
323
326
|
* Space Complexity: O(n)
|
|
324
327
|
*/
|
|
325
328
|
/**
|
|
326
|
-
* Time Complexity: O(n)
|
|
329
|
+
* Time Complexity: O(n)
|
|
327
330
|
* Space Complexity: O(n)
|
|
328
331
|
*
|
|
329
332
|
* The `toArray` function converts a linked list into an array.
|
|
@@ -331,17 +334,31 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
331
334
|
*/
|
|
332
335
|
toArray(): E[];
|
|
333
336
|
/**
|
|
334
|
-
* Time Complexity: O(n)
|
|
337
|
+
* Time Complexity: O(n)
|
|
335
338
|
* Space Complexity: O(n)
|
|
336
339
|
*/
|
|
337
340
|
/**
|
|
338
|
-
* Time Complexity: O(n)
|
|
341
|
+
* Time Complexity: O(n)
|
|
339
342
|
* Space Complexity: O(n)
|
|
340
343
|
*
|
|
341
344
|
* The `toReversedArray` function converts a doubly linked list into an array in reverse order.
|
|
342
345
|
* @returns The `toReversedArray()` function returns an array of type `E[]`.
|
|
343
346
|
*/
|
|
344
347
|
toReversedArray(): E[];
|
|
348
|
+
/**
|
|
349
|
+
* Time Complexity: O(n)
|
|
350
|
+
* Space Complexity: O(n)
|
|
351
|
+
*/
|
|
352
|
+
/**
|
|
353
|
+
* Time Complexity: O(n)
|
|
354
|
+
* Space Complexity: O(n)
|
|
355
|
+
*
|
|
356
|
+
* The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
|
|
357
|
+
* as the original list.
|
|
358
|
+
* @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
|
|
359
|
+
* is a copy of the original list.
|
|
360
|
+
*/
|
|
361
|
+
clone(): DoublyLinkedList<E>;
|
|
345
362
|
/**
|
|
346
363
|
* Time Complexity: O(1)
|
|
347
364
|
* Space Complexity: O(1)
|
|
@@ -412,7 +429,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
412
429
|
*/
|
|
413
430
|
pollLast(): E | undefined;
|
|
414
431
|
/**
|
|
415
|
-
* Time Complexity: O(n)
|
|
432
|
+
* Time Complexity: O(n)
|
|
416
433
|
* Space Complexity: O(1)
|
|
417
434
|
*/
|
|
418
435
|
/**
|
|
@@ -425,7 +442,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
425
442
|
*/
|
|
426
443
|
pollFirst(): E | undefined;
|
|
427
444
|
/**
|
|
428
|
-
* Time Complexity: O(n)
|
|
445
|
+
* Time Complexity: O(n)
|
|
429
446
|
* Space Complexity: O(1)
|
|
430
447
|
*/
|
|
431
448
|
/**
|