-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue.java
43 lines (43 loc) · 1014 Bytes
/
queue.java
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
import java.util.*;
class queue{
static int q[]=new int[10],front=-1,rear=-1;
//push
static void enqueue(int item){
rear++;
if (rear==10)
System.out.println("queue is full");
else
q[rear]=item;
if(front==-1)
front++;
}
//pop
static void dequeue(){
if(front==-1)
System.out.println("queue is empty");
else{
if(front==rear)
front=rear=-1;
else{
for(int i=front;i<rear;i++)
q[i]=q[i+1];
}
}
}
//print all
static void display(){
if (front==-1)
System.out.println("queue is empty");
else{
for(int i=front;i<=rear;i++)
System.out.println(q[i]);
}
}
public static void main(String arg[]){
// try with this
enqueue(1);
enqueue(2);
enqueue(3);
display();
}
}