Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a generic class ArrayQueue that implements the Queue Abstract Data Typ

ID: 3620987 • Letter: I

Question

Implement a generic class ArrayQueue that implements the Queue Abstract Data Type using arrays. It should allocate an array of some reasonable initial size and allocate a new array of double size anytime the old array overflows. You should also implement the circular array implementation that is discussed in the book. Namely, if there is free space at the beginning of the array and the back pointer reached the end of the array, it should wrap around to the beginning on the next enqueue operation.

You do not have to shrink the array when the queue gets very small. The class should be generic. As you know, Java does not allow allocation of generic arrays. To allocate an array of generic type T, you have to allocate an array of type Object and then case it to T[], as follows:

T [] array = (T[]) new Object [10];

Ignore the warning that will be generated by the compiler. Create a simple driver class that tests the implementation of the Queue by using enqueue and dequeue operations and printing the output of the queue (the item that you get back from the dequeue operation).

Explanation / Answer

Dear, Giving you ArrayQueue class based on this derive test program public class ArrayQueue implements Queue { private final static int CAPACITY = 100; private int capacity; private Object[] Q; private int f; private int r; public ArrayQueue() { this(CAPACITY); } public ArrayQueue(int _capacity) { capacity = _capacity; Q = new Object[capacity]; f = r = 0; } public int size() { return (capacity-f+r) % capacity; } public boolean isEmpty() { return size()
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote