-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
49 lines (49 loc) · 1 KB
/
Queue.java
File metadata and controls
49 lines (49 loc) · 1 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
import java.util.*;
public class Queue
{
int que[]=new int[100]; int capacity,front,rear;
Queue()
{
for(int i=0;i<100;i++)
que[i]=0;
}
Queue(int limit)
{
capacity = limit;
front=0;
rear=-1;
}
void dataPush(int num)
{
if(rear == capacity)
System.out.println("Queue is Full");
else
{
rear++;
que[rear]=num;
}
}
int dataPop()
{
if(rear==-1 || front>rear)
{
System.out.println("Queue is Empty.");
return -9999;
}
else
{
int x=que[front];
++front;
return x;
}
}void QueueDisplay()
{
if(rear==-1 || front>rear)
System.out.println("Queue Underflow!");
else
{
System.out.println("The Queue:");
for(int i=front;i<=rear;i++)
System.out.print(que[i] + "\t");
}
}}