-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQUEU.java
89 lines (80 loc) · 1.87 KB
/
QUEU.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.util.*;
public class QUEU {
int size=5;
int items[]=new int[size];
int front, rear;
QUEU(){
front =-1;
rear = -1;
}
boolean isFull(){
if(rear==size-1){
return true;
}
return false;
}
boolean isEmpt(){
if(front ==-1){
return true;
}
return false;
}
void enQ(int element){
if(isFull()){
System.out.println("Queu is full");
}else{
if(front==-1)
front=0;
rear++;
items[rear]=element;
System.out.println("Inserted "+element);
}
}
int deQ(){
int element;
if(isEmpt()){
System.out.println("The queu is empty");
return (-1);
}
else{
element=items[front];
if(front>=rear){
front=-1;
rear=-1;
}
else{
front++;
}
System.out.println("Deleted - > "+element);
return element;
}
}
void display(){
int i;
if(isEmpt()){
System.out.println("Empty Queue");
}
else{
System.out.println("\nFront index -> "+front);
System.out.println("Item -> ");
for(i=front;i<rear;i++){
System.out.println(items[i]+" ");
}
System.out.println("\nRear index -> "+rear);
}
}
public static void main(String[] args) {
QUEU q = new QUEU();
q.display();
q.deQ();
q.enQ(1);
q.enQ(2);
q.enQ(3);
q.enQ(4);
q.enQ(5);
q.enQ(6);
q.display();
q.deQ();
q.display();
}
}