-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA-lab4(a)-Queue
More file actions
48 lines (43 loc) · 959 Bytes
/
DSA-lab4(a)-Queue
File metadata and controls
48 lines (43 loc) · 959 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
public class Main {
public final int max = 4;
public int[] arr = new int[max];
public int f = -1;
public int r = -1;
public void enque(int data) {
if (r == max - 1) {
System.out.println("Overflow");
return;
}
if (f == -1) {
f = 0;
}
r++;
arr[r] = data;
}
public void deque() {
if (f == -1 || f > r) {
System.out.println("Underflow");
return;
}
if (f == r) {
System.out.println("Last Remaining Element: " + arr[f]);
f = -1;
r = -1;
} else {
f++;
}
}
public static void main(String[] args) {
Main q = new Main();
q.enque(10);
q.enque(20);
q.enque(30);
q.enque(40);
q.enque(50);
q.deque();
q.deque();
q.deque();
q.deque();
q.deque();
}
}