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 3c30de9 commit 8ecaf2aCopy full SHA for 8ecaf2a
group07/724319952/src/cn/fyl/first/Stack.java
@@ -0,0 +1,39 @@
1
+package cn.fyl.first;
2
+
3
+public class Stack {
4
5
+ private ArrayList elementData = new ArrayList();
6
+ int last;
7
8
+ public void push(Object o) {
9
+ elementData.add(o);
10
+ }
11
12
+ public Object pop() {
13
+ return elementData.remove(last-1);
14
15
16
+ public Object peek() {
17
+ last = elementData.size()-1;
18
+ return elementData.get(last);
19
20
21
+ public boolean isEmpty() {
22
+ if(elementData.size() > 0)
23
+ return false;
24
+ else
25
+ return true;
26
27
28
+ public int size() {
29
+ return elementData.size();
30
31
32
+ public static void main(String[] args) {
33
+ Stack s = new Stack();
34
+ s.push(1);
35
+ s.push(2);
36
+ s.push(3);
37
+ System.out.println(s.peek());
38
39
+}
0 commit comments