0
/ 50
For the question below, assume the following implementation of ArrayQueue:
public class ArrayQueue<T> implements QueueInterface...
For the question below, assume the following implementation of ArrayQueue:
public class ArrayQueue<T> implements QueueInterface<T> {
private T[] contents;
private int frontIndex;
private int backIndex;
private static final int DEFAULT_CAPACITY = 50;
public ArrayQueue() {
this(DEFAULT_CAPACITY);
}
@SuppressWarnings("unchecked")
public ArrayQueue(int initialCapacity) {
// The new array contains null entries
contents = (T[])new Object[initialCapacity + 1];
frontIndex = 0;
backIndex = contents.length - 1;
}
@Override
public void enqueue(T newEntry) {
// TODO Auto-generated method stub
}
@Override
public T dequeue() {
// TODO Auto-generated method stub
return null;
}
@Override
public T getFront() {
if (isEmpty()) {
throw new EmptyQueueException();
}
return contents[frontIndex];
}
@Override
public boolean isEmpty() {
return (((backIndex + 1) % contents.length) == frontIndex);
}
@Override
public void clear() {
while (!isEmpty()) {
dequeue();
}
}
}
For this question you will be working with an array queue of strings that has already been instantiated and had some values enqueued:
ArrayQueue <String> arr = new ArrayQueue <String>(6);
arr.enqueue("red");
arr.enqueue("red");
arr.enqueue("red");
Thus, the contents
array currently looks like this:
["red", "red", "red", null, null, null, null]
Using only enqueue and dequeue, transform the contents
array to look like this:
["violet", null, "red", "orange", "yellow", "green", "blue"]
Your feedback will appear here when you check your answer.