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 ed5ac51 commit 48f21ebCopy full SHA for 48f21eb
lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12/Stack.java
@@ -10,17 +10,29 @@ public Stack() {
10
11
public void push(int value) {
12
// Your code here
13
+ ListNode newNode = ListNode(value);
14
+ newNode.next = top;
15
+ top = newNode;
16
}
17
18
public int pop() {
- return 0;
19
+ if (isEmpty()) {
20
+ throw new RuntimeException("Stack is empty! Cannot pop.");
21
+ }
22
+ int value = top.val;
23
+ top = top.next;
24
+ return value;
25
26
27
public int peek() {
28
29
+ throw new RuntimeException("Stack is empty! Cannot peek.");
30
31
+ return top.val;
32
-
33
+
34
public boolean isEmpty() {
- return true;
35
+ return top == null;
36
37
38
0 commit comments