Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug in ArryaQueue #92

Closed
haoluoluo opened this issue Jul 25, 2018 · 1 comment
Closed

Possible bug in ArryaQueue #92

haoluoluo opened this issue Jul 25, 2018 · 1 comment

Comments

@haoluoluo
Copy link

haoluoluo commented Jul 25, 2018

function next in ArrayQueueIterator maybe happen ArrayIndexOutOfBoundsException;
because "queue.firstIndex+index" maybe not the real index
public T next() {
if (queue.firstIndex+index < queue.lastIndex) {
last = queue.firstIndex+index;
return queue.array[queue.firstIndex+index++];
//this is my change
// return queue.array[(queue.firstIndex+index++) % queue.array.length];
}
return null;
}

this is a simple test
IQueue arrayQueue = new Queue.ArrayQueue();
for(int i=0;i<1024;i++){

        arrayQueue.offer(i);
    }
    System.out.println(arrayQueue.poll());
    arrayQueue.offer(1024);
    Iterator it = arrayQueue.toQueue().iterator();
    while (it.hasNext()){
        System.out.println(it.next());
    }
@phishman3579
Copy link
Owner

That is absolutely a bug and your fix is the correct solution. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants