循环队列java实现

public class SeqHeap
{
    Object[] data;
    int font;
    int rear;
    int maxSize;

    public SeqHeap(int  maxSize)
    {
        this.maxSize = maxSize;
        this.data = new Object[this.maxSize];
        this.font=0;
        this.rear=0;
    }

    public boolean isEmpty()
    {   
        return this.font==this.rear;
    }

    public boolean isFull()
    {
        return (this.rear+1)%this.maxSize == this.font;
    }
    public void push(Object e)
    {
        if(this.isFull()) return ;
        this.data[this.rear] = e;
        this.rear=(this.rear+1)%this.maxSize;
    }
    public Object pop()
    {
        if(this.isEmpty()) return null;
        Object o = this.data[this.font];
        this.font = (this.font+1)%this.maxSize;
        return o;
    }

    public static void main(String[] args)
    {
        SeqHeap mSeqHeap = new SeqHeap(100);
        for(int i=0;i<10;i++)
            mSeqHeap.push(new Integer(i+1));
        while(mSeqHeap.isEmpty()==false)
            System.out.print((Integer)mSeqHeap.pop()+"\t");

    }
}
posted @ 2016-07-21 19:40  岳麓丹枫  阅读(86)  评论(0编辑  收藏  举报