We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c9740c commit 3a66016Copy full SHA for 3a66016
yoonexample/src/main/java/stack/ListStack.java
@@ -1,5 +1,7 @@
1
package stack;
2
3
+import java.util.EmptyStackException;
4
+
5
public class ListStack<E> implements Stack<E> {
6
7
private int size;
@@ -25,12 +27,21 @@ public void push(E data) {
25
27
26
28
@Override
29
public E pop() {
- return null;
30
+ if (isEmpty()) {
31
+ throw new EmptyStackException();
32
+ }
33
+ Node<E> tmpNode = this.head;
34
+ this.head = this.head.next;
35
+ size--;
36
+ return tmpNode.data;
37
}
38
39
40
public E peek() {
41
42
43
44
+ return this.head.data;
45
46
47
private static class Node<T> {
0 commit comments