Question: In JAVA Add the following methods to the LinkedQueue class, and create a test driver for each to show that they work correctly. In order

In JAVA

Add the following methods to the LinkedQueue class, and create a test driver for each to show that they work correctly. In order to practice your linked list coding skills, code each of these methods by accessing the internal variables of the LinkedQueue, not by calling the previously defined public methods of the class.

String toString() creates and returns a string that correctly represents the current queue. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each queued element already provides its own reasonable toString method.

void remove(int count) removes the front count elements from the queue; throws QueueUnderflowException if less than count elements are in the queue.

boolean swapStart() returns false if less than two elements are in the queue, otherwise reverses the order of the front two elements in the queue and returns true.

boolean swapEnds() returns false if there are less than two elements in the queue, otherwise swaps the first and last elements of the queue and returns true.

//---------------------------------------------------------------------------

// LinkedQueue.java by Dale/Joyce/Weems Chapter 4

//

// Implements QueueInterface using a linked list.

//---------------------------------------------------------------------------

package ch04.queues;

import support.LLNode;

public class LinkedQueue implements QueueInterface

{

protected LLNode front; // reference to the front of this queue

protected LLNode rear; // reference to the rear of this queue

protected int numElements = 0; // number of elements in this queue

public LinkedQueue()

{

front = null; rear = null;

}

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!