I am trying to implement a CircularArrayQueue and my method isEmpty() is returning false when the queue isn't populated. Can you point out my error?
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;
}