Skip to content

Instantly share code, notes, and snippets.

@cangevine
Created October 2, 2014 02:40
Show Gist options
  • Save cangevine/b007a42d3255c31d69a1 to your computer and use it in GitHub Desktop.
Save cangevine/b007a42d3255c31d69a1 to your computer and use it in GitHub Desktop.
Test your Stack implementation
// Notice: the Node should have a toString() method
// which returns the <content> instance variable
void setup() {
Node a = new Node("123");
Node b = new Node("456");
Node c = new Node("789");
Stack s = new Stack();
s.push(a);
s.push(b);
println(s.getLength()); // should return 2
println(s.pop()); // should return "456"
s.push(c);
println(s.getLength()); // should return 2
println(s.peek()); // should return "789"
println(s.pop()); // should return "789"
println(s.isEmpty()); // should return false
println(s.pop()); // should return "123"
println(s.isEmpty()); // should return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment