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 d71b421 commit 88e407fCopy full SHA for 88e407f
yoonexample/src/main/java/stack/ArrayStack.java
@@ -1,5 +1,7 @@
1
package stack;
2
3
+import java.util.EmptyStackException;
4
+
5
public class ArrayStack<E> implements Stack<E> {
6
7
private static final int INITIAL_CAPACITY = 100;
@@ -24,16 +26,24 @@ public boolean isEmpty() {
24
26
25
27
@Override
28
public void push(E data) {
-
29
+ this.topIndex++;
30
+ arr[topIndex] = data;
31
}
32
33
34
public E pop() {
- return null;
35
+ if (isEmpty()) {
36
+ throw new EmptyStackException();
37
+ }
38
+ this.topIndex--;
39
+ return (E) arr[topIndex + 1];
40
41
42
43
public E peek() {
44
45
46
47
+ return (E) arr[topIndex];
48
49
0 commit comments