-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularQueue.java
More file actions
38 lines (32 loc) · 903 Bytes
/
Copy pathCircularQueue.java
File metadata and controls
38 lines (32 loc) · 903 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
package qpack;
public class CircularQueue implements ICharQ {
private char q[];
private int putloc, getloc;
public CircularQueue(int size) {
q = new char[size + 1];
putloc = getloc = 0;
}
public void put(char ch) {
if(putloc + 1 == getloc | ((putloc == q.length - 1) & (getloc == 0))) {
System.out.println(" - Queue is full");
return;
}
putloc++;
if(putloc == q.length) putloc = 0;
q[putloc] = ch;
}
public char get() {
if(getloc == putloc) {
System.out.println(" - Queue is empty");
return (char) 0;
}
getloc++;
if(getloc == q.length) getloc = 0;
return q[getloc];
}
public void reset() {
int newSize = q.length;
q = new char[newSize + 1];
putloc = getloc = 0;
}
}