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