Skip to content

Commit 69ab826

Browse files
committed
feat: Adds game results & stack
1 parent b51637f commit 69ab826

File tree

1 file changed

+11
-4
lines changed
  • lesson_12/structs_java/structs_app/src/main/java/com/codedifferently/lesson12

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ public Stack() {
99
}
1010

1111
public void push(int value) {
12-
// Your code here
12+
ListNode first = new ListNode(value);
13+
first.next = top;
14+
top = first;
1315
}
1416

1517
public int pop() {
16-
return 0;
18+
if (isEmpty()) {
19+
return -1;
20+
}
21+
int value = top.val;
22+
top = top.next;
23+
return value;
1724
}
1825

1926
public int peek() {
20-
return 0;
27+
return top.val;
2128
}
2229

2330
public boolean isEmpty() {
24-
return true;
31+
return top == null;
2532
}
2633
}

0 commit comments

Comments
 (0)