Skip to content
Snippets Groups Projects
Commit bf43b1ee authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

robust pop()

parent 4ae79849
Branches
No related tags found
No related merge requests found
import java.util.EmptyStackException;
public class MyStack { public class MyStack {
private Node top; private Node top;
...@@ -16,6 +18,7 @@ public class MyStack { ...@@ -16,6 +18,7 @@ public class MyStack {
} }
public Object pop() { public Object pop() {
if (size() == 0) throw new EmptyStackException();
Object payload = top.getPayload(); Object payload = top.getPayload();
top = top.getPrevious(); top = top.getPrevious();
return payload; return payload;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment