/************************************************
Hello! This is a playground for binary trees.
Write JavaScript here, then click the "Run" button
to step through your code. On the right hand side,
you'll see any trees that are in scope.
For it to work, you must build your trees using
the provided TreeNode constructor. You can also
use the convenience buildTree function. See the
code below for usage.
Note: this is an alpha version, and a lot of things
don't work. Notably, only one binary tree at a time
will be displayed.
The code is on GitHub:
http://github.com/kasrak/treevis
************************************************/
function binarySearch(node, value) {
if (!node || node.value == value) {
return node;
} else if (node.value < value) {
return binarySearch(node.right, value);
} else {
return binarySearch(node.left, value);
}
}
function addNode(tree, value) {
if (!tree) {
return TreeNode(value);
} else if (tree.value < value) {
tree.right = addNode(tree.right, value);
} else {
tree.left = addNode(tree.left, value);
}
return tree;
}
var root = buildTree([10, [5, [2], [7]],