This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Trie() { | |
| this.head = { | |
| key : '' | |
| , children: {} | |
| } | |
| } | |
| Trie.prototype.add = function(key) { | |
| var curNode = this.head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Trie() { | |
| this.head = { | |
| key : '' | |
| , children: {} | |
| } | |
| } | |
| Trie.prototype.add = function(key, value) { | |
| var curNode = this.head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Trie() { | |
| this.head = { | |
| key : '' | |
| , children: {} | |
| } | |
| } | |
| Trie.prototype.add = function(key, value) { | |
| var curNode = this.head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DoublyLinkedList { | |
| Node head; | |
| Node tail; | |
| public Node getHead() { | |
| return head; | |
| } | |
| public Node getTail() { | |
| return tail; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Stack() { | |
| this.stack = new Array(); | |
| } | |
| Stack.prototype = { | |
| isEmpty: function() { | |
| return this.stack.length == 0; | |
| }, | |
| pop: function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (token == '(') { | |
| operatorStack.push(token); | |
| } else if (token == ')') { | |
| while(operatorStack.peek() != '(') { | |
| var subtree = createSubtree(operatorStack.pop(), null); | |
| outputStack.push(subtree); | |
| } | |
| operatorStack.pop(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var createSubtree = function createSubtree(operator, tree) { | |
| if (tree == null) { | |
| var right = outputStack.pop(), | |
| left = outputStack.pop(); | |
| tree = new BinaryTreeNode(operator); | |
| tree.right = right instanceof BinaryTreeNode ? right : new BinaryTreeNode(right); | |
| tree.left = left instanceof BinaryTreeNode ? left : new BinaryTreeNode(left); | |
| } else { | |
| var subtree = tree, | |
| left = outputStack.pop(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| if (token.length == 1 && isNaN(token)) { | |
| var operator = createOperator(token); | |
| if (!operatorStack.isEmpty() && operator.lessOrEqualInPrecedenceTo(operatorStack.peek())) { | |
| var subtree = createSubtree(operatorStack.pop(), null); | |
| outputStack.push(subtree); | |
| } | |
| operatorStack.push(operator); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for (var s = 0; s < input.length; ) { | |
| var token; | |
| if (isNaN(input[s])) { | |
| token = input[s]; | |
| s+=1; | |
| } else { | |
| var i = s + 1; | |
| while(i < input.length && !isNaN(input[i])) { | |
| i+=1; | |
| } |
NewerOlder