|
@@ -8,8 +8,25 @@ import java.util.ArrayList;
|
8
|
8
|
*/
|
9
|
9
|
public class Stack<E> {
|
10
|
10
|
private ArrayList elements;
|
11
|
|
-
|
|
11
|
+
|
12
|
12
|
public Stack(){
|
|
13
|
+ this.elements = new ArrayList<E>();
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ public E push(E item) {
|
|
17
|
+ this.elements.add(item);
|
|
18
|
+ return item;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ public E pop() {
|
|
22
|
+ return (E) this.elements.remove(elements.size() - 1);
|
|
23
|
+ }
|
13
|
24
|
|
|
25
|
+ public boolean isEmpty() {
|
|
26
|
+ if (this.elements.size() == 0) {
|
|
27
|
+ return true;
|
|
28
|
+ } else {
|
|
29
|
+ return false;
|
|
30
|
+ }
|
14
|
31
|
}
|
15
|
32
|
}
|