This file contains 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 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 the token is a left parenthesis, then push it onto the stack. | |
If the token is a right parenthesis: | |
Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output stack. | |
Pop the left parenthesis from the stack, but not onto the output queue. |
This file contains 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 evaluate = function(node) { | |
var token = node.data; | |
if (token instanceof Operator) { | |
return token.applyFunction(evaluate(node.left), evaluate(node.right)); | |
} else { | |
return node.data; | |
} | |
} |
This file contains 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 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
Declare BinaryTreeNode result; | |
While there are tokens to be read: | |
Read a token. | |
If the token is a number, then add it to the output stack. | |
If the token is an operator, o1, then: | |
while there is an operator token, o2, at the top of the operator stack, and | |
o1 has precedence less than or equal to that of o2, | |
operator = pop o2 off the operator stack; | |
if result is null: | |
set result's data to operator |
This file contains 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
While there are tokens to be read: | |
Read a token. | |
If the token is a number, then add it to the output queue. | |
If the token is an operator, o1, then: | |
while there is an operator token, o2, at the top of the operator stack, and | |
o1 has precedence less than or equal to that of o2, | |
pop o2 off the stack, onto the output queue; | |
push o1 onto the stack. | |
When there are no more tokens to read: | |
While there are still operator tokens in the stack: |
This file contains 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 deepCompare = function(a,b) { | |
for (var field in b) { | |
if (a.hasOwnProperty(field)){ | |
if (a[field] instanceof Object) { | |
return deepCompare(a[field], b[field]); | |
} else if (a[field] !== b[field]){ | |
return false | |
} | |
} else { | |
return false; |
This file contains 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
/* | |
Write a function that will recursively merge two objects with the following conditions: | |
1.) If a[field] is an array, and b[field] is defined and is not an array, add b[field] to the array | |
2.) If a[field] is an array an b[field] exists but is undefined or null, set a[field] to an empty array | |
3.) If a[filed] is an array and b[field] is an array, set a[field] to b[field] | |
4.) If a[field] exists and b[field] exists but is undefined, delete a[field] | |
5.) If b[field] is a non-complex type (number, string, boolean, et cetera), copy to a[field] | |
*/ | |
var a = { |
This file contains 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 static LinkedList<Integer> largestContinuousSum(int[] array) { | |
if (array.length == 0) return null; | |
LinkedList<Integer> current_path, max_path; | |
int current_sum, max_sum; | |
max_path = current_path = new LinkedList<Integer>(); | |
current_sum = max_sum = Integer.MIN_VALUE; | |
This file contains 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 SummableMatrix { | |
private HashMap<Coordinate, Integer> cache; | |
public SummableMatrix(int[][] matrix) { | |
cache = preprocess(matrix); | |
} | |
public static HashMap<Coordinate, Integer> preprocess(int[][] matrix) { | |
HashMap<Coordinate, Integer> result = new HashMap<Coordinate, Integer>(); |