Question: JAVA data structures 1. Complete the implementations of the a. ArrayQueue dequeue isEmpty 2. Include a toString method for the Queue implementation 3. Include a
JAVA data structures
1. Complete the implementations of the a. ArrayQueue dequeue isEmpty 2. Include a toString method for the Queue implementation 3. Include a size() method for the Queue implementation. This method should return the number of elements in the queue (not the maximum capacity) 4. Update the queue tester including a. isEmpty method true and false b. dequeue - with/without exception for all c. toString - at various points before/after queue and dequeue
ArrayQueue Java
package ch05.queues;
public class ArrayQueue
protected T[] queue;
protected int front;
protected int rear;
protected int numElements = 0;
protected final int DEFCAP = 100;
public ArrayQueue() {
queue = (T[]) new Object[DEFCAP];
rear = DEFCAP - 1;
}
public ArrayQueue(int capacity) {
queue = (T[]) new Object[capacity];
rear = capacity - 1;
}
@Override
public T dequeue() throws QueueUnderflowException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void enqueue(T element) throws QueueOverflowException {
// TODO Auto-generated method stub
if (isFull()) {
throw new QueueOverflowException("Queue is full");
}
rear = (rear + 1) % queue.length;
queue[rear] = element;
numElements++;
}
@Override
public boolean isFull() {
// TODO Auto-generated method stub
return (numElements == queue.length);
}
}
QueueTester Java Class
package ch05;
import ch05.queues.*;
public class QueueTester {
public static void main(String[] args) throws QueueUnderflowException {
// TODO Auto-generated method stub
LinkedQueue
lQ.enqueue("a");
lQ.enqueue("b");
System.out.printf("dequeue %s ", lQ.dequeue());
System.out.printf("dequeue %s ", lQ.dequeue());
System.out.printf("dequeue %s ", lQ.dequeue());
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
