new Tree(root)
A Tree has a root which is an object of class TreeNode.
Parameters:
Name | Type | Description |
---|---|---|
root |
TreeNode | The root node of the tree |
- Source:
Methods
calculateDepth() → {number}
Calculate max depth of tree and count the number of nodes.
- Source:
Returns:
Max tree depth
- Type
- number
copy() → {Tree}
Copy the tree.
- Source:
Returns:
A copy of the tree
- Type
- Tree
depthFirst(root, depth, nodes)
Recursively collect by pre-order depth-first left-to-right traversal.
Parameters:
Name | Type | Description |
---|---|---|
root |
TreeNode | Start of traversal |
depth |
number | Depth of tree |
nodes |
array | The tree nodes and their depths in traversal order |
- Source: