Question: ArrayQueue: import exceptions.EmptyCollectionException; public class ArrayQueue implements QueueADT { private T queueArray[]; // Array holding queue private static final int DEFAULT_SIZE = 5; private int

 ArrayQueue: import exceptions.EmptyCollectionException; public class ArrayQueue implements QueueADT { private T

ArrayQueue:

import exceptions.EmptyCollectionException;

public class ArrayQueue implements QueueADT {

private T queueArray[]; // Array holding queue private static final int DEFAULT_SIZE = 5; private int front; // position of element at the front of the queue private int rear; // First free position at rear of the queue private int size; // number of elements in the queue

@SuppressWarnings("unchecked") public ArrayQueue(int initialSize) { front = -1; rear = 0; queueArray = (T[]) new Object[initialSize]; }

public ArrayQueue() { this(DEFAULT_SIZE); }

@Override public void enqueue(T element) { // TODO Auto-generated method stub if (isFull()) { growQueue(); }

if (isEmpty()) { front = (front + 1) % queueArray.length; }

queueArray[rear] = element; rear = (rear + 1) % queueArray.length; size++;

}

private void growQueue() { // TODO Auto-generated method stub

}

@Override public T dequeue() { // TODO Auto-generated method stub if (isEmpty()) { throw new EmptyCollectionException("array queue"); } T retElement = queueArray[front]; queueArray[front] = null; front = (front + 1) % queueArray.length; size--; return retElement; }

@Override public T first() { // TODO Auto-generated method stub if (isEmpty()) { throw new EmptyCollectionException("array queue"); } return queueArray[front]; }

@Override public boolean isEmpty() { // TODO Auto-generated method stub return (size == 0); }

private boolean isFull() { return (size == queueArray.length); }

@Override public int size() { // TODO Auto-generated method stub return size; }

public String toString() { String retString = "["; int index = front;

for (int c = 0; c

retString += "]"; return retString; }

}

QueueADT:

public interface QueueADT {

public void enqueue(T element); public T dequeue(); public T first(); public boolean isEmpty(); public int size(); }

1. Complete the growQueue() method a. Increase the size of the new array by the DEFAULT_SIZE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!