Question
LinkedQueue Code: public class LinkedQueue implements QueueADT { private LNode front; private LNode rear; private int size; public LinkedQueue() { front = null; rear =
LinkedQueue Code:
public class LinkedQueue
private LNode
public LinkedQueue() { front = null; rear = null; size = 0; }
@Override public void enqueue(T element) { // TODO Auto-generated method stub
LNode
@Override public T dequeue() { // TODO Auto-generated method stub T retData; if (isEmpty()) { throw new EmptyCollectionException("linked queue"); } else {
retData = front.getData(); front = front.getNext(); size--; return retData; } }
@Override public T first() { // TODO Auto-generated method stub if (isEmpty()) { throw new EmptyCollectionException("linked queue"); } else {
return front.getData(); } }
@Override public boolean isEmpty() { // TODO Auto-generated method stub return (size == 0); }
@Override public int size() { // TODO Auto-generated method stub return size; }
public String toString() { String retString = "["; LNode
}
QueueADT:
public interface QueueADT
public void enqueue(T element); public T dequeue(); public T first(); public boolean isEmpty(); public int size(); }
+ toArray(T[] anArray) : void - Returns an array containing all of the elements in this queue in proper sequence (from front to rear element). This method may throw the following exceptions: a. NullPointerException - if the array is null use the java NullPointerException) b. ArrayCapacityException- if the size of the array is not sufficient to store the elements of the queue (create this exception)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started