-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackb.java
More file actions
37 lines (34 loc) · 871 Bytes
/
Copy pathstackb.java
File metadata and controls
37 lines (34 loc) · 871 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.ArrayList;
public class stackb {
static class stack {
static ArrayList<Integer> list = new ArrayList<>();
//isEmpty
public static boolean isEmpty(){
return list.size() == 0;
}
//push
public static void push(int data) {
list.add(data);
}
//pop
public static int pop(){
int top = list.get(list.size()-1);
list.remove(list.size()-1);
return top;
}
// peek
public static int peek() {
return list.get(list.size()-1);
}
}
public static void main(String[] args) {
stack s = new stack();
s.push(1);
s.push(2);
s.push(3);
while(!s.isEmpty()) {
System.out.println(s.peek());
s.pop();
}
}
}