-
Notifications
You must be signed in to change notification settings - Fork 824
/
LoopQueue.java
51 lines (41 loc) · 1.05 KB
/
LoopQueue.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
public class LoopQueue<E> implements Queue<E> {
private E[] data;
private int front, tail;
private int size; // 有兴趣的同学,在完成这一章后,可以思考一下:
// LoopQueue中不声明size,如何完成所有的逻辑?
// 这个问题可能会比大家想象的要难一点点:)
public LoopQueue(int capacity){
data = (E[])new Object[capacity + 1];
front = 0;
tail = 0;
size = 0;
}
public LoopQueue(){
this(10);
}
public int getCapacity(){
return data.length - 1;
}
@Override
public boolean isEmpty(){
return front == tail;
}
@Override
public int getSize(){
return size;
}
// 下一小节再做具体实现
@Override
public void enqueue(E e){
}
// 下一小节再做具体实现
@Override
public E dequeue(){
return null;
}
// 下一小节再做具体实现
@Override
public E getFront(){
return null;
}
}