-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCQueue1.java
More file actions
49 lines (47 loc) · 785 Bytes
/
Copy pathCQueue1.java
File metadata and controls
49 lines (47 loc) · 785 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 CQueue1
{
int a[],f,r,n;
CQueue1(int nn)
{
n=nn;
f=-1;
r=-1;
a=new int[n];
}
void push(int v)
{
if((f==0&&r==n-1)||(f==r+1))
System.out.println("OverFlow");
else if(r<0)
{
f=r=0;
a[r]=v;
}
else if(r==n-1)
{
r=0;
a[r]=v;
}
else
a[++r]=v;
}
int pop()
{
int k=-99;
if(f<0)
System.out.println("UnderFlow");
else if(f==r)
{
k=a[f];
f=r=-1;
}
else if(f==n-1)
{
k=a[f];
f=0;
}
else
k=a[f++];
return k;
}
}