-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
51 lines (47 loc) · 772 Bytes
/
Stack.java
File metadata and controls
51 lines (47 loc) · 772 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
46
47
48
49
50
51
import java.util.*;
public class Stack<E> {
private Vector<E> v;
public Stack(){
v = new Vector<E>(0);
}
public Stack(int size){
v = new Vector<E>(size);
}
public void push(E a){
v.add(a);
}
public E pop(){
if(!v.isEmpty()){
return v.remove(v.size()-1);
}
else{
return null;
}
}
public E peek(){
if(!v.isEmpty()){
return v.lastElement();
}
else{
return null;
}
}
public int size(){
return v.size();
}
public boolean isEmpty(){
return v.isEmpty();
}
public void print(){
for(int i = 0;i<v.size();i++){
System.out.print(v.get(i)+ " ");
}
System.out.println();
}
public int lastIndexOf(E element){
return v.lastIndexOf(element);
}
public boolean contains(E element) {
return v.contains(element);
}
}