@itpropro/tree-structure-ts / Exports / Tree
Represents a tree data structure.
Name |
---|
T |
• new Tree<T
>(value
)
Creates a new Tree
instance.
Name |
---|
T |
Name | Type | Description |
---|---|---|
value |
T |
The value to initialize the root node with. |
• root: null
| TreeNode
<T
>
The root node of the tree.
▸ all(): TreeNode
<T
>[]
Returns all the nodes of the tree in an array.
TreeNode
<T
>[]
▸ traverse(callback
, traversal
): undefined
| Promise
<void
[]>
Traverses the tree using the specified traversal method, calling the provided callback function on each visited node.
Name | Type | Description |
---|---|---|
callback |
(node : TreeNode <T >) => void |
A function to call on each visited node. |
traversal |
"breadthFirst" | "depthFirst" | "preOrder" | "postOrder" |
The traversal method to use. Can be one of: 'breadthFirst', 'depthFirst', 'preOrder', 'postOrder'. |
undefined
| Promise
<void
[]>