Class Tree<T>

Represents a tree data structure.

Type Parameters

  • T

    The type of data stored in the tree.

Hierarchy

  • Tree

Constructors

Properties

Accessors

Methods

Constructors

  • Creates a new tree with the specified data as the root node.

    Type Parameters

    • T

    Parameters

    • data: T

      The data to be stored in the root node.

    Returns Tree<T>

Properties

root: TreeLeaf<T>

The root node of the tree.

Accessors

Methods

  • Searches the tree for a node with the specified data and returns the node if found.

    Parameters

    • value: T

      The data to search for.

    Returns undefined | TreeLeaf<T>

    The node with the specified data, or undefined if not found.

  • Traverses the tree in the specified order and returns an array of the visited nodes' data.

    Parameters

    • order: "post" | "pre" | "in" | "height" = "pre"

      The order in which to traverse the tree. Defaults to "pre".

    Returns T[]

    An array of the visited nodes' data.