-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_using_arraylist.java
More file actions
53 lines (38 loc) · 898 Bytes
/
Stack_using_arraylist.java
File metadata and controls
53 lines (38 loc) · 898 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
52
53
import java.util.*;
public class Stack_using_arraylist{
public static void main(String args[]){
stack s=new stack();
System.out.println(s.isEmpty());
s.push(1);
System.out.println(s.isEmpty());
s.pop();
System.out.println(s.peak());
}
}
class stack{
static ArrayList<Integer> list =new ArrayList<>();
//checking the stack
public boolean isEmpty(){
return list.size()==0;
}
//push
public void push(int data){
list.add(data);
}
//pop
public int pop(){
if(list.size()==0){
return -1;
}
int top=list.get(list.size()-1);
list.remove(list.size()-1);
return top;
}
//peak
public int peak(){
if(list.size()==0){
return -1;
}
return list.get(list.size()-1);
}
}