forked from CI2692-AJ2022/interfaces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStackArrayList.java
More file actions
29 lines (26 loc) · 778 Bytes
/
MyStackArrayList.java
File metadata and controls
29 lines (26 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.ArrayList;
public class MyStackArrayList implements MyStackInterface {
public ArrayList<Integer> arrayListStack = new ArrayList<>();
@Override
public void push(int item) {
arrayListStack.add(item);
}
@Override
public Integer pop() {
boolean empty = arrayListStack.isEmpty();
if (!empty) {
int numberRemoved = arrayListStack.get(arrayListStack.size() - 1);
arrayListStack.remove(arrayListStack.size() - 1);
return numberRemoved;
}
return null;
}
@Override
public Integer peek() {
if (arrayListStack.size() > 0) {
return arrayListStack.get(arrayListStack.size() - 1);
} else {
return null;
}
}
}