Class BinarySearchTree<T>

Class representing a Binary Search Tree (BST). A BST is a binary tree where each node has up to two children, and all nodes in the left subtree have values less than the node’s value, while nodes in the right subtree have values greater.

Type Parameters

  • T

    The type of values stored in the tree nodes.

Constructors

Properties

root: BinarySearchTreeNode<T> = null

Root node of the binary search tree, or null if the tree is empty.

Methods

  • Generator function for in-order traversal of the tree. Yields each node's value in ascending sorted order.

    Returns Generator<T, any, any>

    • An iterator for the tree.
  • Inserts a value into the binary search tree. By default, does not allow duplicate values.

    Parameters

    • value: T

      The value to be inserted.

    • OptionalallowDuplicates: boolean = false

      Flag to allow or disallow duplicate values.

    Returns void