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 9807ec1 commit f2be857Copy full SHA for f2be857
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java
@@ -1,5 +1,7 @@
1
package com.codedifferently.lesson12;
2
3
+import java.util.EmptyStackException;
4
+
5
/** Implement the below Stack by providing code for the class methods. */
6
public class Stack {
7
private ListNode top;
@@ -15,12 +17,18 @@ public void push(int value) {
15
17
}
16
18
19
public int pop() {
20
+ if (isEmpty()) {
21
+ throw new EmptyStackException();
22
+ }
23
int value = top.val;
24
top = top.next;
25
return value;
26
27
28
public int peek() {
29
30
31
32
return top.val;
33
34
0 commit comments