5-------队列

public class Queue {
private int MaxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
public Queue(int s){
MaxSize=s;
queArray=new long[MaxSize];
front=0;
rear=-1;
nItems=0;//队列中元素数量
}
public void insert( long j){
if(rear==MaxSize-1){
rear=-1;
}
queArray[++rear]=j;
nItems++;
}
public long remove(){
long temp=queArray[front++];
if(front==MaxSize){
front=0;
}
nItems--;
return temp;
}
public long peekFront(){
return queArray[front];
}
public boolean isEmpty(){
return (nItems==0);
}
public boolean isFull(){
return (nItems==MaxSize);
}
public int size(){
return nItems;
}




}

posted @ 2016-10-03 14:12  一天到晚游泳的fish  阅读(95)  评论(0)    收藏  举报