min-heap-typed 1.42.8 → 1.43.0
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 +88 -23
- package/dist/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/data-structures/binary-tree/binary-tree.js +415 -236
- package/dist/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/data-structures/binary-tree/bst.js +121 -67
- package/dist/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/data-structures/graph/abstract-graph.js +147 -36
- package/dist/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/data-structures/graph/directed-graph.js +126 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/data-structures/graph/undirected-graph.js +63 -0
- package/dist/data-structures/heap/heap.d.ts +175 -12
- package/dist/data-structures/heap/heap.js +175 -12
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/data-structures/queue/deque.d.ts +113 -3
- package/dist/data-structures/queue/deque.js +113 -3
- package/dist/data-structures/queue/queue.d.ts +87 -0
- package/dist/data-structures/queue/queue.js +87 -0
- package/dist/data-structures/stack/stack.d.ts +42 -0
- package/dist/data-structures/stack/stack.js +42 -0
- package/dist/data-structures/trie/trie.d.ts +76 -0
- package/dist/data-structures/trie/trie.js +76 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +97 -23
- package/src/data-structures/binary-tree/binary-tree.ts +465 -256
- package/src/data-structures/binary-tree/bst.ts +130 -68
- package/src/data-structures/binary-tree/rb-tree.ts +106 -19
- package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
- package/src/data-structures/graph/abstract-graph.ts +133 -7
- package/src/data-structures/graph/directed-graph.ts +145 -1
- package/src/data-structures/graph/undirected-graph.ts +72 -0
- package/src/data-structures/heap/heap.ts +201 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
- package/src/data-structures/queue/deque.ts +127 -3
- package/src/data-structures/queue/queue.ts +99 -0
- package/src/data-structures/stack/stack.ts +48 -0
- package/src/data-structures/trie/trie.ts +87 -4
|
@@ -87,24 +87,51 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
87
87
|
*/
|
|
88
88
|
createNode(key: BTNKey, value?: V): N;
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
|
|
90
|
+
* Time Complexity: O(n)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
* Comments: The time complexity for adding a node depends on the depth of the tree. In the best case (when the tree is empty), it's O(1). In the worst case (when the tree is a degenerate tree), it's O(n). The space complexity is constant.
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Time Complexity: O(n)
|
|
96
|
+
* Space Complexity: O(1)
|
|
97
|
+
*
|
|
98
|
+
* The `add` function adds a new node with a key and value to a binary tree, or updates the value of
|
|
99
|
+
* an existing node with the same key.
|
|
100
|
+
* @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be one of the
|
|
101
|
+
* following types:
|
|
102
|
+
* @param {V} [value] - The value to be associated with the key or node being added to the binary
|
|
103
|
+
* tree.
|
|
104
|
+
* @returns The function `add` returns a node (`N`) if it was successfully inserted into the binary
|
|
105
|
+
* tree, or `null` or `undefined` if the insertion was not successful.
|
|
94
106
|
*/
|
|
95
107
|
add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | null | undefined;
|
|
96
108
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
109
|
+
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
110
|
+
* Space Complexity: O(1)
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
114
|
+
* Space Complexity: O(1)
|
|
115
|
+
*
|
|
116
|
+
* The `addMany` function takes an array of keys or nodes and an optional array of values, and adds
|
|
117
|
+
* each key-value pair to a data structure.
|
|
118
|
+
* @param {(BTNKey | N |null | undefined)[]} keysOrNodes - An array of keys or nodes to be added to
|
|
119
|
+
* the binary search tree. Each element can be of type `BTNKey` (a key value), `N` (a node), `null`,
|
|
120
|
+
* or `undefined`.
|
|
121
|
+
* @param {(V | undefined)[]} [values] - The `values` parameter is an optional array of values that
|
|
122
|
+
* correspond to the keys or nodes being added. If provided, the values will be associated with the
|
|
123
|
+
* keys or nodes during the add operation.
|
|
104
124
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
105
125
|
*/
|
|
106
126
|
addMany(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): (N | null | undefined)[];
|
|
107
127
|
/**
|
|
128
|
+
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
129
|
+
* Space Complexity: O(1)
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
133
|
+
* Space Complexity: O(1)
|
|
134
|
+
*
|
|
108
135
|
* The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
|
|
109
136
|
* @param {(BTNKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
|
|
110
137
|
* `BTNKey` or `N` values.
|
|
@@ -118,48 +145,76 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
118
145
|
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
|
|
119
146
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BiTreeDeleteResult<N>[];
|
|
120
147
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* of a node in
|
|
129
|
-
*
|
|
148
|
+
* Time Complexity: O(n)
|
|
149
|
+
* Space Complexity: O(1)
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* Time Complexity: O(n)
|
|
153
|
+
* Space Complexity: O(1)
|
|
154
|
+
*
|
|
155
|
+
* The function calculates the depth of a given node in a binary tree.
|
|
156
|
+
* @param {BTNKey | N | null | undefined} distNode - The `distNode` parameter represents the node in
|
|
157
|
+
* the binary tree whose depth we want to find. It can be of type `BTNKey`, `N`, `null`, or
|
|
158
|
+
* `undefined`.
|
|
159
|
+
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
160
|
+
* from which we want to calculate the depth. It can be either a `BTNKey` (binary tree node key) or
|
|
161
|
+
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
|
|
130
162
|
* @returns the depth of the `distNode` relative to the `beginRoot`.
|
|
131
163
|
*/
|
|
132
164
|
getDepth(distNode: BTNKey | N | null | undefined, beginRoot?: BTNKey | N | null | undefined): number;
|
|
133
165
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
166
|
+
* Time Complexity: O(n)
|
|
167
|
+
* Space Complexity: O(log n)
|
|
168
|
+
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
|
|
169
|
+
*/
|
|
170
|
+
/**
|
|
171
|
+
* Time Complexity: O(n)
|
|
172
|
+
* Space Complexity: O(log n)
|
|
173
|
+
*
|
|
174
|
+
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
|
|
175
|
+
* iterative traversal.
|
|
136
176
|
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
137
|
-
* starting node from which
|
|
138
|
-
*
|
|
139
|
-
* node is specified. If `
|
|
177
|
+
* starting node of the binary tree from which we want to calculate the height. It can be of type
|
|
178
|
+
* `BTNKey`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
|
|
140
179
|
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
|
|
141
|
-
* height of the
|
|
142
|
-
*
|
|
180
|
+
* height of the tree using a recursive approach or an iterative approach. It can have two possible
|
|
181
|
+
* values:
|
|
143
182
|
* @returns the height of the binary tree.
|
|
144
183
|
*/
|
|
145
184
|
getHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
|
|
146
185
|
/**
|
|
186
|
+
* Time Complexity: O(n)
|
|
187
|
+
* Space Complexity: O(log n)
|
|
188
|
+
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
* Time Complexity: O(n)
|
|
192
|
+
* Space Complexity: O(log n)
|
|
193
|
+
*
|
|
147
194
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
148
195
|
* recursive or iterative approach.
|
|
149
|
-
* @param {N | null | undefined} beginRoot - The `beginRoot` parameter
|
|
150
|
-
*
|
|
151
|
-
*
|
|
196
|
+
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
197
|
+
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
|
|
198
|
+
* type `BTNKey`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
|
|
152
199
|
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
|
|
153
200
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
154
201
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
155
202
|
*/
|
|
156
203
|
getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
|
|
157
204
|
/**
|
|
205
|
+
* Time Complexity: O(n)
|
|
206
|
+
* Space Complexity: O(log n)
|
|
207
|
+
*/
|
|
208
|
+
/**
|
|
209
|
+
* Time Complexity: O(n)
|
|
210
|
+
* Space Complexity: O(log n)
|
|
211
|
+
*
|
|
158
212
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
159
213
|
* height of the tree.
|
|
160
|
-
* @param {N | null | undefined} beginRoot - The
|
|
161
|
-
*
|
|
162
|
-
*
|
|
214
|
+
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
215
|
+
* for calculating the height and minimum height of a binary tree. It can be either a `BTNKey` (a key
|
|
216
|
+
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
|
|
217
|
+
* @returns a boolean value.
|
|
163
218
|
*/
|
|
164
219
|
isPerfectlyBalanced(beginRoot?: BTNKey | N | null | undefined): boolean;
|
|
165
220
|
getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
|
|
@@ -172,6 +227,13 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
172
227
|
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
173
228
|
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
174
229
|
/**
|
|
230
|
+
* Time Complexity: O(n)
|
|
231
|
+
* Space Complexity: O(log n)
|
|
232
|
+
*/
|
|
233
|
+
/**
|
|
234
|
+
* Time Complexity: O(n)
|
|
235
|
+
* Space Complexity: O(log n)
|
|
236
|
+
*
|
|
175
237
|
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
|
|
176
238
|
* recursive or iterative iteration.
|
|
177
239
|
* @param {BTNKey} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
@@ -208,56 +270,93 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
208
270
|
*/
|
|
209
271
|
isEmpty(): boolean;
|
|
210
272
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
|
|
214
|
-
|
|
273
|
+
* Time Complexity: O(log n)
|
|
274
|
+
* Space Complexity: O(log n)
|
|
275
|
+
*/
|
|
276
|
+
/**
|
|
277
|
+
* Time Complexity: O(log n)
|
|
278
|
+
* Space Complexity: O(log n)
|
|
279
|
+
*
|
|
280
|
+
* The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
|
|
281
|
+
* structure, with the option to reverse the order of the nodes.
|
|
282
|
+
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
283
|
+
* starting node from which you want to find the path to the root. It can be of type `BTNKey`, `N`,
|
|
284
|
+
* `null`, or `undefined`.
|
|
215
285
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
216
286
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
217
|
-
* reversed before returning it. If `isReverse` is set to `false
|
|
218
|
-
* @returns The function `getPathToRoot` returns an array of
|
|
287
|
+
* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
|
|
288
|
+
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
|
|
219
289
|
*/
|
|
220
290
|
getPathToRoot(beginRoot: BTNKey | N | null | undefined, isReverse?: boolean): N[];
|
|
221
291
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
292
|
+
* Time Complexity: O(log n)
|
|
293
|
+
* Space Complexity: O(1)
|
|
294
|
+
*/
|
|
295
|
+
/**
|
|
296
|
+
* Time Complexity: O(log n)
|
|
297
|
+
* Space Complexity: O(1)
|
|
298
|
+
*
|
|
299
|
+
* The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
|
|
300
|
+
* iteratively.
|
|
224
301
|
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
225
|
-
* for finding the leftmost node in a binary tree. It can be either a
|
|
226
|
-
*
|
|
302
|
+
* for finding the leftmost node in a binary tree. It can be either a `BTNKey` (a key value), `N` (a
|
|
303
|
+
* node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
|
|
227
304
|
* @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
|
|
228
305
|
* be performed when finding the leftmost node in a binary tree. It can have two possible values:
|
|
229
|
-
* @returns The function `getLeftMost` returns the leftmost node (`N`) in
|
|
230
|
-
* no leftmost node, it returns `null
|
|
306
|
+
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
|
|
307
|
+
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
231
308
|
*/
|
|
232
309
|
getLeftMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
233
310
|
/**
|
|
311
|
+
* Time Complexity: O(log n)
|
|
312
|
+
* Space Complexity: O(1)
|
|
313
|
+
*/
|
|
314
|
+
/**
|
|
315
|
+
* Time Complexity: O(log n)
|
|
316
|
+
* Space Complexity: O(1)
|
|
317
|
+
*
|
|
234
318
|
* The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
|
|
235
319
|
* iteratively.
|
|
236
|
-
* @param {N | null | undefined} beginRoot - The `beginRoot` parameter
|
|
237
|
-
*
|
|
238
|
-
* or `
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* `
|
|
320
|
+
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
321
|
+
* starting node from which we want to find the rightmost node. It can be of type `BTNKey`, `N`,
|
|
322
|
+
* `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
|
|
323
|
+
* current object.
|
|
324
|
+
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
325
|
+
* type of iteration to use when finding the rightmost node. It can have one of two values:
|
|
326
|
+
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
|
|
327
|
+
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
243
328
|
*/
|
|
244
329
|
getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
245
330
|
/**
|
|
331
|
+
* Time Complexity: O(n)
|
|
332
|
+
* Space Complexity: O(1)
|
|
333
|
+
*/
|
|
334
|
+
/**
|
|
335
|
+
* Time Complexity: O(n)
|
|
336
|
+
* Space Complexity: O(1)
|
|
337
|
+
*
|
|
246
338
|
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
|
|
247
|
-
* @param {N} beginRoot - The `beginRoot` parameter
|
|
248
|
-
* to check if it is a
|
|
339
|
+
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
|
|
340
|
+
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
|
|
249
341
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
250
342
|
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
|
|
251
343
|
* possible values:
|
|
252
|
-
* @returns
|
|
344
|
+
* @returns a boolean value.
|
|
253
345
|
*/
|
|
254
346
|
isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
255
347
|
/**
|
|
348
|
+
* Time Complexity: O(n)
|
|
349
|
+
* Space Complexity: O(1)
|
|
350
|
+
*/
|
|
351
|
+
/**
|
|
352
|
+
* Time Complexity: O(n)
|
|
353
|
+
* Space Complexity: O(1)
|
|
354
|
+
*
|
|
256
355
|
* The function checks if a binary tree is a binary search tree.
|
|
257
356
|
* @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
|
|
258
357
|
* be used when checking if the binary tree is a binary search tree (BST). It is an optional
|
|
259
|
-
* parameter with a default value of "this.iterationType". The value of "this.iterationType" is
|
|
260
|
-
*
|
|
358
|
+
* parameter with a default value of "this.iterationType". The value of "this.iterationType" is
|
|
359
|
+
* expected to be
|
|
261
360
|
* @returns a boolean value.
|
|
262
361
|
*/
|
|
263
362
|
isBST(iterationType?: IterationType): boolean;
|
|
@@ -301,26 +400,33 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
301
400
|
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
302
401
|
getPredecessor(node: N): N;
|
|
303
402
|
/**
|
|
304
|
-
* The function `getSuccessor` returns the next node in a binary tree given a node
|
|
305
|
-
* `x`
|
|
306
|
-
* @
|
|
307
|
-
*
|
|
308
|
-
* if there is no successor, or `undefined` if the input `x` is `undefined`.
|
|
403
|
+
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
404
|
+
* @param {BTNKey | N | null} [x] - The parameter `x` can be of type `BTNKey`, `N`, or `null`.
|
|
405
|
+
* @returns the successor of the given node or key. The successor is the node that comes immediately
|
|
406
|
+
* after the given node in the inorder traversal of the binary tree.
|
|
309
407
|
*/
|
|
310
408
|
getSuccessor(x?: BTNKey | N | null): N | null | undefined;
|
|
311
409
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
*
|
|
410
|
+
* Time complexity: O(n)
|
|
411
|
+
* Space complexity: O(1)
|
|
412
|
+
*/
|
|
413
|
+
/**
|
|
414
|
+
* Time complexity: O(n)
|
|
415
|
+
* Space complexity: O(1)
|
|
416
|
+
* The `morris` function performs a depth-first traversal on a binary tree using the Morris traversal
|
|
417
|
+
* algorithm.
|
|
418
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
419
|
+
* the tree. It takes a single parameter of type `N` (the type of the nodes in the tree) and returns
|
|
420
|
+
* a value of any type.
|
|
317
421
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
318
422
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
319
423
|
* following values:
|
|
320
|
-
* @param {N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
321
|
-
* traversal. It
|
|
322
|
-
*
|
|
323
|
-
* @returns The `morris`
|
|
424
|
+
* @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
425
|
+
* for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
|
|
426
|
+
* the root of the tree. If no value is provided, the default value is the root of the tree.
|
|
427
|
+
* @returns The function `morris` returns an array of values that are the result of invoking the
|
|
428
|
+
* `callback` function on each node in the binary tree. The type of the array elements is determined
|
|
429
|
+
* by the return type of the `callback` function.
|
|
324
430
|
*/
|
|
325
431
|
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined): ReturnType<C>[];
|
|
326
432
|
/**
|
|
@@ -362,9 +468,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
362
468
|
protected _setRoot(v: N | null | undefined): void;
|
|
363
469
|
/**
|
|
364
470
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
365
|
-
* @param {N | null | undefined} root - The `root` parameter
|
|
366
|
-
* root node of a binary tree.
|
|
367
|
-
*
|
|
471
|
+
* @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null |
|
|
472
|
+
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
473
|
+
* following types:
|
|
368
474
|
*/
|
|
369
475
|
print(beginRoot?: BTNKey | N | null | undefined): void;
|
|
370
476
|
}
|