- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
Latest commit
45 lines (38 loc) · 933 Bytes
/
Copy pathStack.java
File metadata and controls
45 lines (38 loc) · 933 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
importjava.util.NoSuchElementException;
importjava.util.ArrayList;
publicclassStack<T> implementsStackADT<T> {
privateArrayList<T> data;
publicStack() {
data = newArrayList<T>();
}
publicvoidpush(Titem) {
data.add(item);
}
publicTpop() throwsNoSuchElementException {
Tret = data.get(data.size()-1);
data.remove(data.size()-1);
returnret;
}
publicTtop() throwsNoSuchElementException {
returndata.get(data.size()-1);
}
publicStack<T> clone() {
Stack<T> ret = newStack<T>();
for(Ti:data) {
ret.push(i);
}
returnret;
}
publicintsize() {
returndata.size();
}
publicbooleanisEmpty() {
if(data.size() > 0) {
returnfalse;
}
returntrue;
}
publicvoidclear() {
data = newArrayList<T>();
}
}