我想實現一個CircularArrayQueue和我的方法的isEmpty()的返回false。你能指出我的錯誤嗎?的Java CircularArrayQueue的isEmpty方法
public CircularArrayQueue(int size)
{
array = new Integer[size];
front = rear = 0;
}
... code omitted
// returns the number of elements in the queue
@Override
public int noItems()
{
return array.length - getCapacityLeft();
}
// returns true if the queue is empty
@Override
public boolean isEmpty()
{
return noItems() == 0;
}
//returns the number of available spots in the queue before a resize needs to be done
public int getCapacityLeft()
{
return (array.length - rear + front)%array.length;
}
你昨天發佈了同樣的問題? –