Vamonos.DataStructure.BinaryTree

Back

Experimental. BinaryTree takes a tree encoded as nested objects of the form { val, id, left, right } where left and right are optional objects of the same form.

Public Interface

addNode(targetId, direction, newNode)

adds newNode as the direction child of the node matching targetId

asGraph()

returns an equivalent Vamonos.DataStructure.Graph

changeVal(targetId, newVal)

changes the val field of the node matching targetId to newVal

deleteNode(targetId)

deletes the node matching targetId, preforming rotations as necessary

eachNodeInOrder(f)

applies f to each node using an in-order traversal

eachNodePostOrder(f)

applies f to each node using a post-order traversal

eachNodePreOrder(f)

applies f to each node using a pre-order traversal

rotateLeft(id)

rotates the tree left at the node matching id

rotateRight(id)

rotates the tree right at the node matching id