简单队列实现
@Data
public class ArrayQueue {
private int size;
private int font;
private int ref;
private int[] arr;
public void init(int maxSize) {
size = maxSize;
arr = new int[maxSize];
ref = -1;
font = -1;
}
public Boolean isEmpty() {
if (font == ref) {
return true;
} else {
return false;
}
}
public Boolean isFull() {
if (ref +1== size) {
return true;
} else {
return false;
}
}
public int add(int num) {
if (isFull()) {
throw new RuntimeException("队列已经满");
} else {
ref++;
arr[ref] = num;
return num;
}
}
public int get() {
if (isEmpty()) {
throw new RuntimeException("队列已空");
}
font++;
return arr[font];
}