I think your issue is caused by the noItems
method:
@Override
public int noItems() {
if(rear > front)
return rear - front;
return N - front + rear;
}
After 1000 insertions the Queue size is now 2000, but N
is final
and is still 1000. Change N by Queue.length
.
PS: Java conventions recommend variables and attributes should start with lowercase: at first glance I was looking for the Queue class definition and its length static field :P