queue wrapping bug fixes
All checks were successful
sample gradle build and test / build (pull_request) Successful in 1m3s
All checks were successful
sample gradle build and test / build (pull_request) Successful in 1m3s
This commit is contained in:
parent
026b6c1d09
commit
e24ed7cf50
@ -6,7 +6,7 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class ArrayQueue<E> extends Queue<E>{
|
||||
|
||||
private E[] queueArray = (E[]) new Object[1];
|
||||
private E[] queueArray = (E[]) new Object[5];
|
||||
private int startPtr;
|
||||
private int endPtr;
|
||||
private int size;
|
||||
@ -50,8 +50,9 @@ public class ArrayQueue<E> extends Queue<E>{
|
||||
int oldArraySize = tempArray.length;
|
||||
queueArray = (E[]) new Object[targetSize];
|
||||
int j = 0;
|
||||
for(int i=startPtr; i<endPtr; i++)
|
||||
queueArray[j++]=tempArray[i];
|
||||
|
||||
for(int i=0; i<size; i++)
|
||||
queueArray[j++]=tempArray[(startPtr+i)%oldArraySize];
|
||||
endPtr = size();
|
||||
startPtr = 0;
|
||||
queueArrayLength = queueArray.length;
|
||||
@ -69,12 +70,12 @@ public class ArrayQueue<E> extends Queue<E>{
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iteratorIndex<endPtr;
|
||||
return iteratorIndex % queueArrayLength < endPtr % queueArrayLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E next() {
|
||||
return queueArray[iteratorIndex++];
|
||||
return queueArray[iteratorIndex++ % queueArrayLength];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user