Skip to content
On this page

Tree<T>

A tree data structure.

Constructors

OverloadDescription
new Tree(): Tree<T>

Properties

NameDescription
rootReturns the root node of the tree.

Methods

NameDescription
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>): voidTraverses the tree using BFS.
traverseDFS(callback: CallBackFn<T>, startNode: TreeNode<T>): voidTraverses the tree using DFS.