-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathIQDemo2.java
82 lines (66 loc) · 2.12 KB
/
IQDemo2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.guide.c8;
import com.guide.c8.qpack.FixedQueue;
import com.guide.c8.qpack.DynQueue;
import com.guide.c8.qpack.CircularQueue;
import com.guide.c8.qpack.ICharQ;
// Demonstrate the ICharQ interface.
public class IQDemo2 {
public static void main(String[] args) {
FixedQueue q1 = new FixedQueue(10);
DynQueue q2 = new DynQueue(5);
CircularQueue q3 = new CircularQueue(10);
ICharQ iQ;
char ch;
int i;
iQ = q1;
// Put some characters into fixed queue.
for (i = 0; i < 10; i++)
iQ.put((char) ('A' + i));
// Show the queue.
System.out.print("Contents of fixed queue: ");
for (i = 0; i < 10; i++) {
ch = iQ.get();
System.out.print(ch);
}
System.out.println();
iQ = q2;
// Put some characters into dynamic queue.
for (i = 0; i < 10; i++)
iQ.put((char) ('Z' - i));
// Show the queue.
System.out.print("Contents of dynamic queue: ");
for (i = 0; i < 10; i++) {
ch = iQ.get();
System.out.print(ch);
}
System.out.println();
iQ = q3;
// Put some characters into circular queue.
for (i = 0; i < 10; i++)
iQ.put((char) ('A' + i));
// Show the queue.
System.out.print("Contents of circular queue: ");
for (i = 0; i < 10; i++) {
ch = iQ.get();
System.out.print(ch);
}
System.out.println();
// Put some characters into circular queue.
for (i = 10; i < 20; i++)
iQ.put((char) ('A' + i));
// Show the queue.
System.out.print("Contents of circular queue: ");
for (i = 0; i < 10; i++) {
ch = iQ.get();
System.out.print(ch);
}
System.out.println("\nStore and consume from circular queue.");
// Store in and consume from circular queue.
for (i = 0; i < 20; i++) {
iQ.put((char) ('A' + i));
ch = iQ.get();
System.out.print(ch);
}
System.out.println();
}
}