Class: BinaryTree

BinaryTree(iterable, comparator)

A non self-balancing, rooted binary tree, whose internal nodes each store a key greater than all the keys in the node's left subtree and less than those in its right subtree.

Constructor

new BinaryTree(iterable, comparator)

Construct a binary tree object
Parameters:
Name Type Description
iterable Array Value used to construct a tree, defaults to null if undefined
comparator function The comparator(val1, val2) function that will be used to compare two values, defaults to aritmetic comparator if undefined
Source:

Members

root :BinaryNode

The root node of this tree
Type:
Source:

Methods

buildTree(iterable)

Build a non self-balancing binary search tree representing an iterable
Parameters:
Name Type Description
iterable Array Value used to construct a tree
Source:

insert(value) → {boolean}

Attempt to insert a value
Parameters:
Name Type Description
value * The value to insert
Source:
Returns:
whether the value was successfully inserted
Type
boolean

isEqual(obj)

Check if an object is equal to this object
Parameters:
Name Type Description
obj * The object that will be compared with this object
Source:

remove(value) → {boolean}

Attempt to remove a value
Parameters:
Name Type Description
value * The value to remove
Source:
Returns:
whether the value was successfully removed
Type
boolean
Search for a value
Parameters:
Name Type Description
value * The value to search for
node BinaryNode The node being evaluated, defaults to this.root if undefined
Source:
Returns:
the node where the value exists, or null if the value does not exist
Type
BinaryNode | null

toArray() → {Array}

Return this tree as a sorted array of values
Source:
Returns:
this tree as a sorted array of values
Type
Array