Skip to content

Instantly share code, notes, and snippets.

@Bjacksonshorts
Created September 30, 2013 03:49
Show Gist options
  • Save Bjacksonshorts/6759166 to your computer and use it in GitHub Desktop.
Save Bjacksonshorts/6759166 to your computer and use it in GitHub Desktop.
var counter = 0;
var n = new Node()
Stack = function(){
This.top = null;
}
Stack.prototype.push = function(){
if( this.top == null){
this.top = n;
}
return this.top;
}
Stack.prototype.pop = function(){
if(this.top != null){
this.top = null;
n.getNextNode = this.top;
}
}
Stack.prototype.peek = function(){
return this.top;
}
Stack.prototype.getLength = function(){
while(Stack.push == true){
counter++;
}
return counter;
}
Stack.prototype.isEmpty = function(n){
if(counter == 0){
return true;
}
}
@cangevine
Copy link

#2, 3: In this class definition, only write the relevant code for the class
#5: the constructor should be written as: function Stack() { ... }
#8: push should take an argument; it should not return anything
#11: What if the top is not null? How will the new top be set? What will the new top's nextNode be?
#16: The top should not be null -- instead it should be the next one down the Stack
#18: pop should return the old top (once it has been removed from the Stack)
#23: This while loop will not work. Would our time from class help with a second draft?
#29: This method does not need to take a parameter, and it should return either true OR false (right now it will only ever return true... or nothing.) Also, the use of the "counter" variable is problematic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment