Question: public interface Queue { public abstract boolean isEmpty(); public abstract int size(); public abstract Object front() throws QueueEmptyException; public abstract void enqueue(Object item) throws QueueFullException;
public interface Queue { public abstract boolean isEmpty(); public abstract int size(); public abstract Object front() throws QueueEmptyException; public abstract void enqueue(Object item) throws QueueFullException; public abstract Object dequeue() throws QueueEmptyException; } public class ArrayQueue implements Queue { public static final int CAPACITY=1000; private int capacity; private Object [ ] array; private int front=0; private int rear=0; public ArrayQueue() { this(CAPACITY); } public ArrayQueue(int cap) { capacity = cap; array = new Object[capacity]; } ... } public class ArrayQueue implements Queue { ... public int size() { return (capacity - front + rear) % capacity; } public boolean isEmpty() { return (front == rear); } public void enqueue (Object item) throws QueueFullException { if (size() == capacity-1) throw new QueueFullException(); array [rear] = item; rear = (rear+1) % capacity; } ... } public class ArrayQueue implements Queue { ... public Object dequeue() throws QueueEmptyException { if (isEmpty()) throw new QueueEmptyException(); Object item = array [front]; array [front] = null; front = (front+1) % capacity; return item; } public Object front() throws QueueEmptyException { if (isEmpty()) throw new QueueEmptyException(); return array[front]; } ... } The above code is accroding to note Ch3.3 Queue, p27-29. Please help to answer the following questino(s) related to ArrayQueue accroding to note Ch3.3 Queue, p27-29. 1.








ArrayQueue q1 = new ArrayQueue (5); q1. enqueue("100"); q1. enqueue("240"); q1.enqueue ("365"); q1.dequeue(); q1.enqueue ("653"); q1.dequeue (); q1.enqueue ("777"); q1. enqueue("520"); After executing the above program statements, The object in the front of the queue q1 is The size of the queue q1 is The front value in the queue q1 is The rear value in the queue q1 is
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
