Created
October 3, 2013 09:41
-
-
Save Bjacksonshorts/6807528 to your computer and use it in GitHub Desktop.
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.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