-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
37 lines (31 loc) · 763 Bytes
/
Stack.java
File metadata and controls
37 lines (31 loc) · 763 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
import java.util.Vector;
public class Stack {
private static Vector<Object> stack = new Vector<Object>();
public static void main(String[] args){
System.out.println(empty());
push("Hello");
System.out.println(empty());
push("What");
push("Hey");
push("Greetings");
push("Steve");
System.out.println(pop());
System.out.println(pop());
System.out.println(peek());
System.out.println(peek());
}
public static boolean empty(){
return stack.isEmpty();
}
public static Object peek(){
return stack.lastElement();
}
public static Object pop(){
Object obj = stack.lastElement();
stack.remove(obj);
return obj;
}
public static void push(Object obj){
stack.addElement(obj);
}
}