I'm trying to implement a circular array queue which can be resized, in order to meet a series of tests.
However I repeatedly fail the tests mainly due to the queue being the wrong size after En-Queuing and De-Queueing, but additionally because the queue failed to resize when it was expected to do so.
I appreciate that initialising the size of the queue to 1000 may be a mistake, but even after debugging it I can't find out what's causing the failure.
If you could help me identify the reasons for the test failures that would be greatly appreciated.
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