Type Parameters

  • V = any

Constructors

Accessors

Methods

Constructors

  • The constructor function initializes a TreeNode object with a key, optional value, and optional children.

    Type Parameters

    • V = any

    Parameters

    • key: string

      A string representing the key of the tree node.

    • Optional value: V

      The value parameter is an optional parameter of type V. It represents the value associated with the node. If no value is provided, it defaults to undefined.

    • Optional children: TreeNode<V>[]

      The children parameter is an optional array of TreeNode<V> objects. It represents the child nodes of the current node. If no children are provided, the default value is an empty array.

    Returns TreeNode<V>

Accessors

  • get children(): undefined | TreeNode<V>[]
  • The function returns an array of TreeNode objects or undefined.

    Returns undefined | TreeNode<V>[]

    The children property is being returned. It is of type TreeNode<V>[] | undefined, which means it can either be an array of TreeNode<V> objects or undefined.

  • set children(value): void
  • The function sets the value of the children property of a TreeNode object.

    Parameters

    • value: undefined | TreeNode<V>[]

      The value parameter is of type TreeNode[] | undefined. This means that it can accept an array of TreeNode objects or undefined.

    Returns void

  • get key(): string
  • The function returns the value of the protected variable _key.

    Returns string

    The value of the _key property, which is a string.

  • set key(value): void
  • The above function sets the value of a protected variable called "key".

    Parameters

    • value: string

      The value parameter is a string that represents the value to be assigned to the key.

    Returns void

  • get value(): undefined | V
  • The function returns the value stored in a variable, or undefined if the variable is empty.

    Returns undefined | V

    The value of the variable _value is being returned.

  • set value(value): void
  • The function sets the value of a variable.

    Parameters

    • value: undefined | V

      The parameter "value" is of type "V | undefined", which means it can accept a value of type "V" or it can be undefined.

    Returns void

Methods

  • The function addChildren adds one or more child nodes to the current node.

    Parameters

    • children: TreeNode<V> | TreeNode<V>[]

      The children parameter can be either a single TreeNode<V> object or an array of TreeNode<V> objects.

    Returns void

  • The function getHeight() calculates the maximum depth of a tree structure by performing a breadth-first search.

    Returns number

    the maximum depth or height of the tree.

Generated using TypeDoc