data-structure-typed 1.36.8 → 1.37.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/CHANGELOG.md +3 -1
- package/README.md +8 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -5
- package/dist/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -95
- package/dist/data-structures/binary-tree/binary-tree.js +82 -183
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +6 -20
- package/dist/data-structures/binary-tree/bst.js +22 -122
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -67
- package/dist/data-structures/binary-tree/tree-multiset.js +10 -257
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +4 -3
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/data-structures/hash/hash-map.js +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +3 -3
- package/dist/data-structures/hash/hash-table.js +3 -3
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -3
- package/dist/data-structures/linked-list/skip-linked-list.js +3 -3
- package/dist/data-structures/queue/deque.d.ts +2 -2
- package/dist/data-structures/queue/deque.js +2 -2
- package/dist/data-structures/queue/queue.js +1 -1
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +2 -2
- package/dist/interfaces/binary-tree.d.ts +1 -1
- package/lib/data-structures/binary-tree/avl-tree.d.ts +5 -5
- package/lib/data-structures/binary-tree/avl-tree.js +6 -6
- package/lib/data-structures/binary-tree/binary-tree.d.ts +18 -95
- package/lib/data-structures/binary-tree/binary-tree.js +82 -183
- package/lib/data-structures/binary-tree/bst.d.ts +6 -20
- package/lib/data-structures/binary-tree/bst.js +22 -122
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +6 -67
- package/lib/data-structures/binary-tree/tree-multiset.js +10 -257
- package/lib/data-structures/graph/abstract-graph.js +4 -3
- package/lib/data-structures/hash/hash-map.d.ts +1 -1
- package/lib/data-structures/hash/hash-map.js +1 -1
- package/lib/data-structures/hash/hash-table.d.ts +3 -3
- package/lib/data-structures/hash/hash-table.js +3 -3
- package/lib/data-structures/linked-list/skip-linked-list.d.ts +3 -3
- package/lib/data-structures/linked-list/skip-linked-list.js +3 -3
- package/lib/data-structures/queue/deque.d.ts +2 -2
- package/lib/data-structures/queue/deque.js +2 -2
- package/lib/data-structures/queue/queue.js +1 -1
- package/lib/data-structures/trie/trie.d.ts +2 -2
- package/lib/data-structures/trie/trie.js +2 -2
- package/lib/interfaces/binary-tree.d.ts +1 -1
- package/package.json +9 -7
- package/src/data-structures/binary-tree/avl-tree.ts +6 -6
- package/src/data-structures/binary-tree/binary-tree.ts +85 -274
- package/src/data-structures/binary-tree/bst.ts +22 -106
- package/src/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/data-structures/binary-tree/tree-multiset.ts +10 -249
- package/src/data-structures/graph/abstract-graph.ts +4 -3
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/hash/hash-table.ts +3 -3
- package/src/data-structures/heap/heap.ts +5 -2
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -3
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/trie/trie.ts +2 -2
- package/src/interfaces/binary-tree.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +19 -17
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/bst.test.ts +72 -35
- package/test/unit/data-structures/binary-tree/overall.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +67 -37
- package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/hash/hash-table.test.ts +5 -5
- package/test/unit/data-structures/heap/heap.test.ts +15 -12
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +7 -7
- package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +20 -3
- package/test/unit/data-structures/queue/queue.test.ts +42 -0
- package/test/unit/data-structures/trie/trie.test.ts +5 -5
- package/test/utils/big-o.ts +64 -57
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,10 +8,12 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v1.
|
|
11
|
+
## [v1.37.0](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
|
|
12
12
|
|
|
13
13
|
### Changes
|
|
14
14
|
|
|
15
|
+
- [binary-tree, graph] Replace all code that uses Arrays as makeshift Q… [`#18`](https://github.com/zrwusa/data-structure-typed/pull/18)
|
|
16
|
+
- 1. No need for dfsIterative; integrate it directly into the dfs metho… [`#17`](https://github.com/zrwusa/data-structure-typed/pull/17)
|
|
15
17
|
- [heap] fibonacci heap implemented. [test] big O estimate. [project] n… [`#15`](https://github.com/zrwusa/data-structure-typed/pull/15)
|
|
16
18
|
- [rbtree] implemented, but with bugs [`#13`](https://github.com/zrwusa/data-structure-typed/pull/13)
|
|
17
19
|
- [trie] renamed ambiguous methods and add comments to all methods. [`#12`](https://github.com/zrwusa/data-structure-typed/pull/12)
|
package/README.md
CHANGED
|
@@ -641,6 +641,14 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
641
641
|
|
|
642
642
|
## Code design
|
|
643
643
|
|
|
644
|
+
### Adhere to ES6 standard naming conventions for APIs.
|
|
645
|
+
|
|
646
|
+
Standardize API conventions by using 'add' and 'delete' for element manipulation methods in all data structures.
|
|
647
|
+
|
|
648
|
+
Opt for concise and clear method names, avoiding excessive length while ensuring explicit intent.
|
|
649
|
+
|
|
650
|
+
### Object-oriented programming(OOP)
|
|
651
|
+
|
|
644
652
|
By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly
|
|
645
653
|
inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the
|
|
646
654
|
optimal approach to data structure design.
|
|
@@ -21,13 +21,13 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> e
|
|
|
21
21
|
*/
|
|
22
22
|
constructor(options?: AVLTreeOptions);
|
|
23
23
|
/**
|
|
24
|
-
* The `
|
|
25
|
-
* @param {N} srcNode - The source node that you want to
|
|
24
|
+
* The `_swap` function swaps the location of two nodes in a binary tree.
|
|
25
|
+
* @param {N} srcNode - The source node that you want to _swap with the destination node.
|
|
26
26
|
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
|
|
27
27
|
* be swapped to.
|
|
28
28
|
* @returns The `destNode` is being returned.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
protected _swap(srcNode: N, destNode: N): N;
|
|
31
31
|
/**
|
|
32
32
|
* The function creates a new AVL tree node with the given key and value.
|
|
33
33
|
* @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
@@ -46,13 +46,13 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> e
|
|
|
46
46
|
*/
|
|
47
47
|
add(key: BinaryTreeNodeKey, val?: N['val']): N | null | undefined;
|
|
48
48
|
/**
|
|
49
|
-
* The function overrides the
|
|
49
|
+
* The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
|
|
50
50
|
* deletion.
|
|
51
51
|
* @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
|
|
52
52
|
* removed.
|
|
53
53
|
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
delete(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
|
|
56
56
|
/**
|
|
57
57
|
* The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
|
|
58
58
|
* height of its right subtree.
|
|
@@ -27,13 +27,13 @@ class AVLTree extends bst_1.BST {
|
|
|
27
27
|
super(options);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* The `
|
|
31
|
-
* @param {N} srcNode - The source node that you want to
|
|
30
|
+
* The `_swap` function swaps the location of two nodes in a binary tree.
|
|
31
|
+
* @param {N} srcNode - The source node that you want to _swap with the destination node.
|
|
32
32
|
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
|
|
33
33
|
* be swapped to.
|
|
34
34
|
* @returns The `destNode` is being returned.
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
_swap(srcNode, destNode) {
|
|
37
37
|
const { key, val, height } = destNode;
|
|
38
38
|
const tempNode = this.createNode(key, val);
|
|
39
39
|
if (tempNode) {
|
|
@@ -73,14 +73,14 @@ class AVLTree extends bst_1.BST {
|
|
|
73
73
|
return inserted;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* The function overrides the
|
|
76
|
+
* The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
|
|
77
77
|
* deletion.
|
|
78
78
|
* @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
|
|
79
79
|
* removed.
|
|
80
80
|
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
81
81
|
*/
|
|
82
|
-
|
|
83
|
-
const deletedResults = super.
|
|
82
|
+
delete(key) {
|
|
83
|
+
const deletedResults = super.delete(key);
|
|
84
84
|
for (const { needBalanced } of deletedResults) {
|
|
85
85
|
if (needBalanced) {
|
|
86
86
|
this._balancePath(needBalanced);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avl-tree.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/avl-tree.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+BAAmC;AAInC,MAAa,WAAmF,SAAQ,aAGvG;IAGC,YAAY,GAAsB,EAAE,GAAO;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAVD,kCAUC;AAED,MAAa,OAA0D,SAAQ,SAAM;IACnF;;;;;OAKG;IACH,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;
|
|
1
|
+
{"version":3,"file":"avl-tree.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/avl-tree.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+BAAmC;AAInC,MAAa,WAAmF,SAAQ,aAGvG;IAGC,YAAY,GAAsB,EAAE,GAAO;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAVD,kCAUC;AAED,MAAa,OAA0D,SAAQ,SAAM;IACnF;;;;;OAKG;IACH,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACgB,KAAK,CAAC,OAAU,EAAE,QAAW;QAC9C,MAAM,EAAC,GAAG,EAAE,GAAG,EAAE,MAA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AAK,GAAG,CAAC,CAAC;iBACrB;aACF;SACF;QAED,IAAI,CAAC;YAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC;YAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;QAC7B,IAAI,CAAC;YAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC;YAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;QAEnB,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;CACF;AAxTD,0BAwTC"}
|
|
@@ -55,17 +55,18 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
55
55
|
get size(): number;
|
|
56
56
|
private _loopType;
|
|
57
57
|
get loopType(): LoopType;
|
|
58
|
+
set loopType(v: LoopType);
|
|
58
59
|
visitedKey: BinaryTreeNodeKey[];
|
|
59
60
|
visitedVal: N['val'][];
|
|
60
61
|
visitedNode: N[];
|
|
61
62
|
/**
|
|
62
|
-
* The `
|
|
63
|
-
* @param {N} srcNode - The source node that you want to
|
|
63
|
+
* The `_swap` function swaps the location of two nodes in a binary tree.
|
|
64
|
+
* @param {N} srcNode - The source node that you want to _swap with the destination node.
|
|
64
65
|
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
|
|
65
66
|
* be swapped to.
|
|
66
67
|
* @returns The `destNode` is being returned.
|
|
67
68
|
*/
|
|
68
|
-
|
|
69
|
+
protected _swap(srcNode: N, destNode: N): N;
|
|
69
70
|
/**
|
|
70
71
|
* The clear() function resets the root, size, and maxKey properties to their initial values.
|
|
71
72
|
*/
|
|
@@ -111,13 +112,13 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
111
112
|
*/
|
|
112
113
|
refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array<N['val']>): boolean;
|
|
113
114
|
/**
|
|
114
|
-
* The `
|
|
115
|
+
* The `delete` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
|
|
115
116
|
* containing the deleted node and the node that needs to be balanced.
|
|
116
117
|
* @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
|
|
117
118
|
* node ID (`BinaryTreeNodeKey`).
|
|
118
|
-
* @returns The function `
|
|
119
|
+
* @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
119
120
|
*/
|
|
120
|
-
|
|
121
|
+
delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
|
|
121
122
|
/**
|
|
122
123
|
* The function calculates the depth of a node in a binary tree.
|
|
123
124
|
* @param {N | BinaryTreeNodeKey | null} distNode - The `distNode` parameter can be any node of the tree
|
|
@@ -236,10 +237,10 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
236
237
|
getRightMost(beginRoot: N): N;
|
|
237
238
|
/**
|
|
238
239
|
* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
|
|
239
|
-
* @param {N | null}
|
|
240
|
+
* @param {N | null} subTreeRoot - The `node` parameter represents the root node of a binary search tree (BST).
|
|
240
241
|
* @returns a boolean value.
|
|
241
242
|
*/
|
|
242
|
-
isSubtreeBST(
|
|
243
|
+
isSubtreeBST(subTreeRoot: N | null): boolean;
|
|
243
244
|
/**
|
|
244
245
|
* The function isBST checks if the binary tree is valid binary search tree.
|
|
245
246
|
* @returns The `isBST()` function is returning a boolean value.
|
|
@@ -253,26 +254,14 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
253
254
|
*/
|
|
254
255
|
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
|
255
256
|
/**
|
|
256
|
-
* The function `
|
|
257
|
-
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
258
|
-
* tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
|
|
259
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
|
|
260
|
-
* property of the binary tree node to use for calculating the sum. It can be either 'key' or 'val'. If propertyName is
|
|
261
|
-
* not provided, it defaults to 'key'.
|
|
262
|
-
* @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
|
|
263
|
-
*/
|
|
264
|
-
subTreeSum(subTreeRoot: N | BinaryTreeNodeKey | null, propertyName?: BinaryTreeNodePropertyName): number;
|
|
265
|
-
/**
|
|
266
|
-
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
|
|
257
|
+
* The function `subTreeForeach` adds a delta value to a specified property of each node in a subtree.
|
|
267
258
|
* @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
268
259
|
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
|
|
269
|
-
* @param
|
|
270
|
-
* each node in the subtree should be incremented.
|
|
271
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
260
|
+
* @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
|
|
272
261
|
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
|
|
273
262
|
* @returns a boolean value.
|
|
274
263
|
*/
|
|
275
|
-
|
|
264
|
+
subTreeForeach(subTreeRoot: N | BinaryTreeNodeKey | null, callback: (node: N) => any): boolean;
|
|
276
265
|
/**
|
|
277
266
|
* Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on their 'key' property.
|
|
278
267
|
* @returns An array of binary tree node IDs.
|
|
@@ -311,87 +300,26 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
311
300
|
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
|
|
312
301
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
313
302
|
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
|
|
303
|
+
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
|
|
314
304
|
* @returns An array of values corresponding to the specified property.
|
|
315
305
|
*/
|
|
316
|
-
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
306
|
+
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key', loopType?: LoopType): BinaryTreeNodeKey[];
|
|
317
307
|
/**
|
|
318
308
|
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
|
|
319
309
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
320
310
|
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
|
|
311
|
+
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
|
|
321
312
|
* @returns An array of 'val' properties from each node.
|
|
322
313
|
*/
|
|
323
|
-
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
|
|
314
|
+
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val', loopType?: LoopType): N[];
|
|
324
315
|
/**
|
|
325
316
|
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
|
|
326
317
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
327
318
|
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
|
|
319
|
+
* @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
|
|
328
320
|
* @returns An array of binary tree nodes.
|
|
329
321
|
*/
|
|
330
|
-
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
|
|
331
|
-
/**
|
|
332
|
-
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
|
|
333
|
-
* @returns An array of binary tree node IDs.
|
|
334
|
-
*/
|
|
335
|
-
dfsIterative(): BinaryTreeNodeKey[];
|
|
336
|
-
/**
|
|
337
|
-
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
|
|
338
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
339
|
-
* @returns An array of values corresponding to the specified property.
|
|
340
|
-
*/
|
|
341
|
-
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
|
|
342
|
-
/**
|
|
343
|
-
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
|
|
344
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
345
|
-
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
|
|
346
|
-
* @returns An array of values corresponding to the specified property.
|
|
347
|
-
*/
|
|
348
|
-
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
349
|
-
/**
|
|
350
|
-
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
|
|
351
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
352
|
-
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
|
|
353
|
-
* @returns An array of 'val' properties from each node.
|
|
354
|
-
*/
|
|
355
|
-
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
|
|
356
|
-
/**
|
|
357
|
-
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
|
|
358
|
-
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
359
|
-
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
|
|
360
|
-
* @returns An array of binary tree nodes.
|
|
361
|
-
*/
|
|
362
|
-
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
|
|
363
|
-
/**
|
|
364
|
-
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
|
|
365
|
-
* @returns An array of binary tree node IDs.
|
|
366
|
-
*/
|
|
367
|
-
levelIterative(): BinaryTreeNodeKey[];
|
|
368
|
-
/**
|
|
369
|
-
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
|
|
370
|
-
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
|
|
371
|
-
* @returns An array of binary tree node IDs.
|
|
372
|
-
*/
|
|
373
|
-
levelIterative(node: N | null): BinaryTreeNodeKey[];
|
|
374
|
-
/**
|
|
375
|
-
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.
|
|
376
|
-
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
|
|
377
|
-
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
|
|
378
|
-
* @returns An array of values corresponding to the specified property.
|
|
379
|
-
*/
|
|
380
|
-
levelIterative(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
381
|
-
/**
|
|
382
|
-
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.
|
|
383
|
-
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
|
|
384
|
-
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
|
|
385
|
-
* @returns An array of 'val' properties from each node.
|
|
386
|
-
*/
|
|
387
|
-
levelIterative(node: N | null, nodeOrPropertyName: 'val'): N['val'][];
|
|
388
|
-
/**
|
|
389
|
-
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.
|
|
390
|
-
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
|
|
391
|
-
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
|
|
392
|
-
* @returns An array of binary tree nodes.
|
|
393
|
-
*/
|
|
394
|
-
levelIterative(node: N | null, nodeOrPropertyName: 'node'): N[];
|
|
322
|
+
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node', loopType?: LoopType): N[];
|
|
395
323
|
/**
|
|
396
324
|
* Collects nodes from a binary tree by a specified property and organizes them into levels.
|
|
397
325
|
* @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.
|
|
@@ -477,11 +405,6 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
477
405
|
* undefined.
|
|
478
406
|
*/
|
|
479
407
|
protected _addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
480
|
-
/**
|
|
481
|
-
* The function sets the loop type for a protected variable.
|
|
482
|
-
* @param {LoopType} value - The value parameter is of type LoopType.
|
|
483
|
-
*/
|
|
484
|
-
protected _setLoopType(value: LoopType): void;
|
|
485
408
|
/**
|
|
486
409
|
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the
|
|
487
410
|
* parent property of the value to undefined.
|