-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueues.java
More file actions
49 lines (49 loc) · 894 Bytes
/
Queues.java
File metadata and controls
49 lines (49 loc) · 894 Bytes
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
public class Queues
{
int q[]=new int[1000];
int max;
int front;
int rear;
Queues(int cap)
{
max=cap;
front=0;
rear=-1;
}
void enqueue(int n)
{
if(rear==max-1)
System.out.println("Queue Overflow");
else
{
rear++;
q[rear]=n;
System.out.println("Item inserted successfully");
}
}
int dequeue()
{
if(rear==-1){
System.out.println("Queue Underflow");
return -9999;
}
else
{
int n=q[front];
front++;
return n;
}
}
void display()
{
if(rear==-1)
System.out.println("Queue Underflow");
else
{
for(int i=rear;i>=front;i--)
{
System.out.print(q[i]);
}
}
}
}