Class: BinaryTree

BinaryTree

Binary tree implementation.

new BinaryTree(name)

Parameters:
Name Type Description
name String The name of the tree
Author:
  • Jakub Melezinek
Source:

Methods

<static> getIndex(node) → {Number}

Simulate array implementation.
Parameters:
Name Type Description
node btv.BinaryTreeNode
Source:
Throws:
Throws exception if given node is null.
Returns:
Index of given node.
Type
Number

build(array)

Parameters:
Name Type Description
array Number[]
Source:

getCount() → {Number}

Source:
Returns:
Type
Number

getName() → {String}

Source:
Returns:
Type
String

getNode(index) → {btv.BinaryTreeNode}

Simulate array implementation.
Parameters:
Name Type Description
index Number
Source:
Throws:
  • Throws exception if this tree doesn't have root node.
  • Throws exception if given index is negative.
Returns:
Type
btv.BinaryTreeNode

getRoot() → {btv.BinaryTreeNode}

Source:
Returns:
Type
btv.BinaryTreeNode

setName(name)

Parameters:
Name Type Description
name String
Source:

setRoot(root)

Parameters:
Name Type Description
root btv.BinaryTreeNode
Source:
Throws:
Throws exception if the given node has a parent.

swapNodes(node1, node2) → {Boolean}

Parameters:
Name Type Description
node1 btv.BinaryTreeNode
node2 btv.BinaryTreeNode
Source:
Returns:
Returns true if nodes was swapped succesfully.
Type
Boolean

toArray() → {btv.BinaryTreeNode[]}

Simulate array implementation.
Source:
Returns:
Type
btv.BinaryTreeNode[]

toInorderArray() → {btv.BinaryTreeNode[]}

Source:
Returns:
Type
btv.BinaryTreeNode[]

toString() → {String}

Source:
Returns:
Type
String