Skip to content

Instantly share code, notes, and snippets.

@jasondscott
Created December 14, 2013 00:45
Show Gist options
  • Save jasondscott/7954188 to your computer and use it in GitHub Desktop.
Save jasondscott/7954188 to your computer and use it in GitHub Desktop.
function Stack() {
var data = [];
var stackPtr = [0,0,0];
this.push = function(stackNumber, d) {
var index = stackNumber + stackPtr[stackNumber] * 3;
data[index] = d;
stackPtr[stackNumber]++;
};
this.print = function() {
var strs = ["","",""];
for (var i = 0; i < data.length; i++) {
console.log(i);
stack = i % 3;
if(data[i]) {
strs[stack] = strs[stack] + " " + data[i];
}
}
console.log("Stack 0:" + strs[0]);
console.log("Stack 1:" + strs[1]);
console.log("Stack 2:" + strs[2]);
};
}
var s = new Stack();
s.push(0, 5);
s.push(0, 2);
s.push(0, 1);
s.push(2, 1);
s.push(2, 1);
s.push(2, 1);
s.push(1, 2);
s.push(1, 2-1);
s.print();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment