Java数据结构和算法(五)——队列

队列,queue,就是现实生活中的排队。


1、简单队列:

public class Queqe {
    private int array[];
    private int front;
    private int end;
    private int number;
    private int max;
    
    private Queqe(int maxsize){
        array = new int[maxsize];
        max = maxsize;
        front = 0;
        end = 0;
        number = 0;
    }
    
    private void insert(int item){
        if(isFull()){
            System.out.println("is full,can not insert");
            return;
        }
        array[end++] = item;
        number++;
    }
    
    private int remove(){
        if(isEmpty()){
            System.out.println("is empty,can not remove");
            return -1;
        }
        number--;
        return array[front++];
    }
    
    private boolean isFull(){
        return number == max;
    }
    private boolean isEmpty()

你可能感兴趣的:(数据结构与算法)