public interface Queue { public abstract boolean isEmpty(); public abstract int size(); public abstract Object front() throws
Fantastic news! We've Found the answer you've been seeking!
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 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.
Related Book For
Introduction To Programming In Java An Interdisciplinary Approach
ISBN: 9780672337840
2nd Edition
Authors: Robert Sedgewick, Kevin Wayne
Posted Date: