Skip to content

Instantly share code, notes, and snippets.

@Bjacksonshorts
Created October 3, 2013 09:41
Show Gist options
  • Save Bjacksonshorts/6807528 to your computer and use it in GitHub Desktop.
Save Bjacksonshorts/6807528 to your computer and use it in GitHub Desktop.
function Stack(){
this.top = null;
this.length = 0;
}
Stack.prototype.push = function(n){
//the new node has to be the top so the old top should become the new node's NextNode because it should be second
n.setNextNode(this.top);
//then you should make the new node the top
this.top = n;
//add one to the counter;
this.length++;
}
Stack.prototype.pop = function(){
if(this.top != null){
this.top = this.top.getNextNode()
this.length--;
return this.top;
}
}
Stack.prototype.peek = function(){
return this.top;
}
Stack.prototype.getLength = function(){
return this.length;
}
Stack.prototype.isEmpty = function(){
if(this.top == null){
return true;
}else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment