-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.java
More file actions
64 lines (63 loc) · 1.52 KB
/
queue.java
File metadata and controls
64 lines (63 loc) · 1.52 KB
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
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
class queuearray{
int r_q,f,limit;static int[] q1;
queuearray(int size){
limit=size;
q1=new int[limit];
}
void enqueue(int value){
if(r_q==limit){
System.out.println("queue full");
}
else
{
q1[r_q]=value;
r_q++;
}
}
void dequeue(){
if(r_q==0){
System.out.println("queue empty");
}
else {
for (int i=0;i<r_q-1;i++) {
q1[i]=q1[i+1];
}
r_q--;
}
}
void display(){
if(r_q==0){
System.out.println("queue empty");
}
else {
for (int i=0;i<r_q;i++) {
System.out.print(q1[i]+" ");
}
}
}
}
public class queue {
static int f,r_q=0,limit,ele,n1;
static int[] q1;
public static void main(String[] args) {
try (Scanner ab = new Scanner(System.in)) {
System.out.println("limit: ");
limit=ab.nextInt();
queuearray ob=new queuearray(limit);
for (int i=0; i<limit;i++)
{
System.out.println("element no :"+(i+1));
ele=ab.nextInt();
ob.enqueue(ele);
}
ob.display();
System.out.println("number of elements to dequeue");
n1=ab.nextInt();
for (int j=0;j<n1;j++){
ob.dequeue();
}
ob.display();
}
}
}