队列
先进先出,只允许在一端进行插入,另一端进行删除 队列是一种操作受限的线性表
循环队列
将队列从逻辑上造成一个环状,利用取余实现
代码
class CircleQueue<T>{
private T[] element;
private int head;
private int tail;
public CircleQueue(){
element = (T[])new Object[10];
}
public void push(T value){
if(tail+1%element.length == head){
element = Arrays.copyOf(element,element.length*2);
}
element[tail++]=value;
tail++;
tail = tail%element.length;
}
public void pop(){
if(head == tail)
{
return;
}
element[head] = null;
head = ++head%element.length;
}
public T peek(){
return element[head];
}
}
今天也要好好学习呀~
|