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(value, node) → {BinaryNode|null}
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