Tree<T>
A tree data structure.
Constructors
Overload | Description |
---|---|
new Tree(): Tree<T> |
Properties
Name | Description |
---|---|
root | Returns the root node of the tree. |
Methods
Name | Description |
---|---|
delete(node: TreeNode<T>): TreeNode<T> | Deletes a node from the tree. |
deserialize(obj: SerializedNode<T>): Tree<T> | This method deserializes a serialized tree into a new Tree. |
insert(value: T | TreeNode<T>, parent: TreeNode<T>): TreeNode<T> | Inserts a new node into the tree. If no parent is specified, the new node becomes the root node. If a parent is specified, the new node is inserted as a child of the parent. Throws an error if a root node already exists and no parent is specified. |
toObject(): null | SerializedNode<T> | This code serializes a node and its children into an object. |
traverseBFS(callback: CallBackFn<T>): void | Traverses the tree using BFS. |
traverseDFS(callback: CallBackFn<T>, startNode: TreeNode<T>): void | Traverses the tree using DFS. |