Created
October 2, 2014 02:40
-
-
Save cangevine/b007a42d3255c31d69a1 to your computer and use it in GitHub Desktop.
Test your Stack implementation
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
// 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