-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.java
59 lines (58 loc) · 938 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Java
class Queue
{
int que[];
int size;
int front;
int rear;
Queue(int mm)
{
size=mm;
front=0;
rear=0;
que=new int[size];
}
void addele(int v)
{
if(rear==size-1)
{
System.out.println("Overflow!");
}
else if(rear==0)
{
front=1;
rear=1;
que[rear]=v;
}
else
{
que[++rear]=v;
}
}
int delete()
{
int val=0;
if(rear==0)
{
val=-9999;
}
else if(front==rear)
{
val=que[front];
front=0;
rear=0;
}
else
{
val=que[front++];
}
return val;
}
void display()
{
for(int i=front;i<=rear;i++)
{
System.out.println(que[i]);
}
}
}