Question: JAVA data structures 1. Complete the implementation of the LinkedQueue 2. Include a toString method for the Queue implementations 3. Include a size() method for
JAVA data structures
1. Complete the implementation of the LinkedQueue 2. Include a toString method for the Queue implementations 3. Include a size() method for the Queue implementations. This method should return the number of elements in the queue (not the maximum capacity) 4. Update the queue tester to include tests for all three queues, including a. isEmpty method true and false b. isFull method empty and false (for the ArrayQueue) c. enqueue with exception for ArrayQueue d. dequeue - with/without exception for all e. toString - at various points before/after queue and dequeue
LinkedQueue Java Class
package ch05.queues;
import support.LLNode;
public class LinkedQueue implements UnboundedQueueInterface {
LLNode front;
LLNode rear;
int numElements;
public LinkedQueue() {
numElements = 0;
}
@Override
public T dequeue() throws QueueUnderflowException {
// TODO Auto-generated method stub
T data;
if (isEmpty())
throw new QueueUnderflowException("Queue is empty");
data = front.getInfo();
front = front.getLink();
if (front == null) {
rear = null;
}
numElements--;
return data;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return (front == null);
}
@Override
public void enqueue(T element) {
// TODO Auto-generated method stub
LLNode newNode = new LLNode(element);
if (isEmpty()) {
front = newNode;
}
else {
rear.setLink(newNode);
}
rear = newNode;
numElements++;
}
}
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 = new 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
