public class MyQueueCircle {
public int elem[];
public int front;
public int rear;
public MyQueueCircle(){
this.elem=new int[10];
}
//入队
public boolean enQueue (int value) {
if (isFull()){
return false;
}
this.elem[this.rear]=value;
this.rear=(this.rear+1)%this.elem.length;
return true;
}
public boolean isFull(){
if ((this.rear+1)%this.elem.length == this.front){
return true;
}return false;
}
public boolean isEmpty(){
if (this.front == this.rear){
return true;
}return false;
}
//出队
public boolean deQueue() {
if (isEmpty()){
return false;
}
this.front= (front+1)%this.elem.length;
return true;
}
//得到队列的队头元素
public int Front() {
if (isEmpty()){
throw new UnsupportedOperationException("队列为空");
}
return this.elem[front];
}
//得到队尾元素
public int Rear(){
if (isEmpty()){
throw new UnsupportedOperationException("队列为空");
}
int index=0;
if (this.rear==0){
index=this.elem.length-1;
}else {
index=this.rear-1;
}return this.elem[index];
}
}