-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTemplate.java
More file actions
49 lines (43 loc) · 946 Bytes
/
Template.java
File metadata and controls
49 lines (43 loc) · 946 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
import java.util.ArrayList;
class Stack<T extends Number>
{
private ArrayList<T> list = new ArrayList<>();
public void push(T data){
list.add(data);
}
public T pop(){
if(list.size()>0){
return list.remove(list.size()-1);
}
else{
return null;
}
}
public void peep(){
for(int i = list.size()-1 ; i>=0; i--){
System.out.println(list.get(i));
}
}
}
public class Template {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Stack<String> stack = new Stack<>();
// stack.push("ram");
// stack.push("shyam");
// stack.push("tom");
// stack.peep();
// stack.pop();
// System.out.println("After Pop");
// stack.peep();
System.out.println("***********************************");
Stack<Integer> stack2 = new Stack<>();
stack2.push(1000);
stack2.push(2000);
stack2.push(3000);
stack2.peep();
stack2.pop();
System.out.println("After Pop");
stack2.peep();
}
}