Skip to content

Instantly share code, notes, and snippets.

@alexandervasyuk
Created October 8, 2014 23:18
Show Gist options
  • Save alexandervasyuk/32b364645d4bbdd3b00c to your computer and use it in GitHub Desktop.
Save alexandervasyuk/32b364645d4bbdd3b00c to your computer and use it in GitHub Desktop.
infixToBinaryUpdateTree
var updateTree = function() {
var operator = operatorStack.pop(),
output = outputStack.pop();
if (head == null) {
head = new BinaryTreeNode(operator);
left = outputStack.pop();
head.left = left instanceof BinaryTreeNode ? left : new BinaryTreeNode(left);
head.right = output instanceof BinaryTreeNode ? output : new BinaryTreeNode(output);
} else {
var subtree = head;
head = new BinaryTreeNode(operator);
head.left = output instanceof BinaryTreeNode ? output : new BinaryTreeNode(output);
head.right = subtree;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment