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
| public class Test {
public static void main(String[] args) {
LoopQueue<Integer> queue = new LoopQueue<>();
for (int i = 0; i < 11; i++) {
queue.enqueue(i);
System.out.println(queue);
}
for (int i = 0; i < 11; i++) {
queue.dequeue();
System.out.println(queue);
}
}
}
输出结果:
LoopQueue: size = 1 , capacity = 10
front [0] tail
LoopQueue: size = 2 , capacity = 10
front [0, 1] tail
LoopQueue: size = 3 , capacity = 10
front [0, 1, 2] tail
LoopQueue: size = 4 , capacity = 10
front [0, 1, 2, 3] tail
LoopQueue: size = 5 , capacity = 10
front [0, 1, 2, 3, 4] tail
LoopQueue: size = 6 , capacity = 10
front [0, 1, 2, 3, 4, 5] tail
LoopQueue: size = 7 , capacity = 10
front [0, 1, 2, 3, 4, 5, 6] tail
LoopQueue: size = 8 , capacity = 10
front [0, 1, 2, 3, 4, 5, 6, 7] tail
LoopQueue: size = 9 , capacity = 10
front [0, 1, 2, 3, 4, 5, 6, 7, 8] tail
LoopQueue: size = 10 , capacity = 10
front [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] tail
LoopQueue: size = 11 , capacity = 20
front [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] tail
LoopQueue: size = 10 , capacity = 20
front [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] tail
LoopQueue: size = 9 , capacity = 20
front [2, 3, 4, 5, 6, 7, 8, 9, 10] tail
LoopQueue: size = 8 , capacity = 20
front [3, 4, 5, 6, 7, 8, 9, 10] tail
LoopQueue: size = 7 , capacity = 20
front [4, 5, 6, 7, 8, 9, 10] tail
LoopQueue: size = 6 , capacity = 20
front [5, 6, 7, 8, 9, 10] tail
LoopQueue: size = 5 , capacity = 20
front [6, 7, 8, 9, 10] tail
LoopQueue: size = 4 , capacity = 10
front [7, 8, 9, 10] tail
LoopQueue: size = 3 , capacity = 10
front [8, 9, 10] tail
LoopQueue: size = 2 , capacity = 10
front [9, 10] tail
LoopQueue: size = 1 , capacity = 5
front [10] tail
LoopQueue: size = 0 , capacity = 2
front [] tail
|