-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA-lab3(a)-stack
More file actions
41 lines (37 loc) · 906 Bytes
/
DSA-lab3(a)-stack
File metadata and controls
41 lines (37 loc) · 906 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
import java.util.*;
public class Main {
public final int max=4;
public int[] arr = new int[max];
public int tos=-1;
public void push (int data){
if (tos==max-1){
System.out.println("overflow");
return; }
tos++;
arr[tos]=data;
System.out.println("Push="+data);
}
public void pop(){
if (tos==-1){
System.out.println("underflow");
return;}
int popd=arr[tos];
tos--;
System.out.println("Pop="+popd);
return;
}
public static void main(String[] args) {
Main stack=new Main();
stack.push(10);
stack.push(20);
stack.push(10);
stack.push(10);
stack.push(50);
stack.push(100);
stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.pop();
}
}