Skip to content

Commit 8ecaf2a

Browse files
author
lgt
committed
test
1 parent 3c30de9 commit 8ecaf2a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)