package Demo;
//性能最优的循环队列
public class Queue {
private int[] data = new int[20];
private int start = 0;
private int end = 0;
public void push(int newint) {
if( end - start == data.length) {
int[] datanew = new int[data.length * 2];
for(int i = 0; i < data.length;i++) {
datanew[i] = data[(start + i) % data.length];
}
start = 0;
end = start + data.length;
data = datanew;
}
data[end % data.length] = newint;
end++;
}
public Integer get() {
if(end == start) {
return null;
}
int result = data[start % data.length];
start++;
return result;
}
}
来源:CSDN
作者:薛习
链接:https://blog.csdn.net/weixin_45681935/article/details/103916173