队列异常处理

时间:2014-05-05 17:24:43

标签: java exception queue

这是我的基于循环链接数组的队列的代码。

public class ArrayQueue{
    private Object[] theArray;
    private int currentSize;
    private int front;
    private int rear;
    static final int DEFAULT_CAPACITY=10;
    public  ArrayQueue(){
        theArray=new Object[DEFAULT_CAPACITY];
        makeEmpty();    
    }
    public void makeEmpty(){
        currentSize=0;
        rear=-1;
        front=0;
    }

public void enqueue(Object x) throws OverFlow{
    if (isFull())
        throw new OverFlow("Array size exceeded");
    else{
        rear=increment(rear);
        theArray[rear]=x;
        currentSize++;
        }
    }

public Object dequeue()throws UnderFlow{
    if (isEmpty())
        throw new UnderFlow("Empty array");
    else{
        Object returnValue=theArray[front];
        theArray[front]=null;//check if this has to be done
        front=increment(front);
        currentSize--;
        return returnValue;
    }
}

public object getFront() throws UnderFlow{
    if (isEmpty())
        throw new UnderFlow("Empty array");
    else
        return theArray[front];

}

public boolean isEmpty(){
    if (currentSize==0)
        return true;
    else
        return false;
}

public boolean isFull(){
    if (currentSize==theArray.length)
        return true;
    else
        return false;
}

public int increment(int x){
    if (x+1==currentSize)
        x=0;
    else
        x++;
    return x; 
    }

}

当我编译这个时,我得到错误,因为找不到符号抛出新的OverFlow。 如何摆脱这个问题。

0 个答案:

没有答案