-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
49 lines (41 loc) · 1.23 KB
/
Queue.java
File metadata and controls
49 lines (41 loc) · 1.23 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
/*The program is to implement queue. TO input the elements to the front of the queue and to delete it.*/
import java.util.*;
public class Queue {
int front, rear, size ;
static int maximum = 1000;
int [] A = new int[maximum];
Queue() {
front = 0;
rear = maximum-1;
}
public boolean isFull(Queue q) {
return (q.size == maximum);
}
public boolean isEmpty(Queue q) {
return (q.size==0);
}
public void enQueue(int data) {
if(isFull(this))
return ;
this.rear = (this.rear + 1)%maximum;
this.A[this.rear] = data;
this.size = this.size+1;
System.out.println(data);
}
//Deleting the elements from front of the queue
public int deQueue() {
if(isEmpty(this))
System.out.println("Queue Underflow! ");
int data = this.A[this.front];
this.front = (this.front + 1)%maximum;
this.size = this.size - 1 ;
return data;
}
public static void main(String[] args) {
Queue Q = new Queue();
Q.enQueue(1);
Q.enQueue(2);
Q.enQueue(3);
System.out.println(Q.deQueue()+ " is dequeued from the queue.");
}
}