手写一个简单的队列

public void RoundQueue{

private long[] a;//队列
private int size;//队列大小
private int nItems;//实际存储容量
private int front;//头
private int rear;//尾

public RoundQueue(int maxSize){
    this.size = maxSize;
    a = new long[size];
    front = 0;
    rear = -1;
    nItems = 0;
}


//添加
public void insert(long value){
    //判断队列是否满了
    if(isFull()){
        System.out.print("队列满了");
        return;
    }
    
    rear = ++rear % size;
    a[rear] = value;
    //实际容量+1
    nItems++;
}

//删除
public long remove(){
    //判断队列是否为空
    if(isEmpty()){
        System.out.print("队列中没有数据");
        return 0;
    }
    front  = front % size;
    nItems--;
    return a[front++];
}

//查询
public void disPlay(){
    //判断队列是否为空
    if(isEmpty()){
        System.out.print("队列中没有数据");
        return;
    }
    
    int item = front;
    for(int i=0;i复制代码

}

你可能感兴趣的:(手写一个简单的队列)