-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathqueueallist.java
More file actions
59 lines (59 loc) · 1.11 KB
/
queueallist.java
File metadata and controls
59 lines (59 loc) · 1.11 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
50
51
52
53
54
55
56
57
58
59
class Queueal<D> implements Queue<D>
{
Integer front,rear,buffer;
Object a[];
Queueal()
{
front=-1;
rear=-1;
buffer=5;
a=new Object[buffer];
}
public void enqueue(D o)
{
if(rear==(buffer-1))
{
Object a2[]=new Object[buffer*2];
buffer*=2;
for(Integer j=front;j<rear;++j)
a2[j]=a[j];
a=a2;
a[++rear]=o;
}
else
{
if(front==-1)
front=0;
a[++rear]=o;
}
}
public D dequeue()
{
try
{
if(front==-1)
{
BoundsException ob=new BoundsException();
throw ob;
}
}
catch(BoundsException x)
{
x.printError();
return null;
}
if(front==rear)
{
front=-1;
rear=-1;
}
return (D)a[front++];
}
public Integer Size()
{
Integer c=0;
for(Integer i=front;i<=rear;++i)
++c;
return c;
}
}