-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackbyll.java
39 lines (34 loc) · 901 Bytes
/
stackbyll.java
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
import java.util.*;
public class stackbyll {
static class Stack{
static ArrayList<Integer> st=new ArrayList<>();
public static boolean isEmpty(){
return st.size()==0;
}
public static void push(int data){
st.add(data);
}
public static int pop(){
if(isEmpty()) return -1;
int top=st.get(st.size()-1);
st.remove(st.size()-1);
return top;
}
public static int peek(){
if(isEmpty()) return -1;
int top=st.get(st.size()-1);
return top;
}
}
public static void main(String[] args) {
Stack s =new Stack();
s.push(1);
s.push(2);
s.push(3);
s.push(4);
while(!s.isEmpty()){
System.out.println(s.peek());
s.pop();
}
}
}