Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LinkedQueue Code: public class LinkedQueue implements QueueADT { private LNode front; private LNode rear; private int size; public LinkedQueue() { front = null; rear =

image text in transcribed

LinkedQueue Code:

public class LinkedQueue implements QueueADT {

private LNode front; private LNode rear; private int size;

public LinkedQueue() { front = null; rear = null; size = 0; }

@Override public void enqueue(T element) { // TODO Auto-generated method stub

LNode newNode = new LNode(element); if (isEmpty()) { rear = newNode; front = newNode; } else { rear.setNext(newNode); rear = newNode; } size++; }

@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 it = front; while (it != null) { retString += it.getData(); retString += " "; it = it.getNext(); } retString += "]"; return retString; }

}

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

Know the different variations of arbitration that are in use

Answered: 1 week ago

Question

5. If yes, then why?

Answered: 1 week ago

Question

3. What changes should I be making?

Answered: 1 week ago