Trees

// Create a new tree by passing the value of the root
var a = Tree('a') 

var b = a.root.addChild('b') // Add child to root
var c = a.root.addChild('c')
var d = a.root.addChild('d')
var e = a.root.addChild('e')

var f = b.addChild('f') // addChild returns the node
var g = b.addChild('g')

var h = c.addChild('h')
var i = g.addChild('i')

console.log(a.display()); // Print a representation of the tree

Binary Trees

// Create a new binary tree by passing the value of the root
var tree = BinaryTree("4") 

var a = tree.root.addChild("2")
var b = tree.root.addChild("5") // addChild returns the node

var c = a.addChild("1")
var d = a.addChild("3")

var e = b.addChild("6") 
var f = b.addChild("7")

// Print in order representation of the tree
console.log(tree.display();

// Print pre order representation of the tree
console.log(tree.display(order.pre);

// Print post order representation of the tree
console.log(tree.display(order.post);

Binary Search Trees

// Create a new binary tree by passing the value of the root
var tree = BinarySearchTree(4) 

var a = tree.root.insert(2) // insert child of root
var b = tree.root.insert(8)

var c = a.insert(1)
var d = a.insert(3) // insert retirns the node

var e = b.insert(5)
var f = b.insert(9)

// Print in order representation of the tree
console.log(tree.display();

// Print pre order representation of the tree
console.log(tree.display(order.pre);

// Print post order representation of the tree
console.log(tree.display(order.post);