Skip to content

Commit f2be857

Browse files
committed
fix
1 parent 9807ec1 commit f2be857

File tree

1 file changed

+8
-0
lines changed
  • lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12

1 file changed

+8
-0
lines changed

lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.codedifferently.lesson12;
22

3+
import java.util.EmptyStackException;
4+
35
/** Implement the below Stack by providing code for the class methods. */
46
public class Stack {
57
private ListNode top;
@@ -15,12 +17,18 @@ public void push(int value) {
1517
}
1618

1719
public int pop() {
20+
if (isEmpty()) {
21+
throw new EmptyStackException();
22+
}
1823
int value = top.val;
1924
top = top.next;
2025
return value;
2126
}
2227

2328
public int peek() {
29+
if (isEmpty()) {
30+
throw new EmptyStackException();
31+
}
2432
return top.val;
2533
}
2634

0 commit comments

Comments
 (0)