Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a splice method from the implementation perspective for the LinkedQueue cl

ID: 3714835 • Letter: W

Question

Write a splice method from the implementation perspective for the LinkedQueue class.

The secondQueue should not be altered when the method completes.

Linked Queue:

public class LinkedQueue<T> implements QueueInterface<T>, java.io.Serializable

{

private Node firstNode; // references node at front of queue

private Node lastNode; // references node at back of queue

public LinkedQueue()

{

firstNode = null;

lastNode = null;

} // end default constructor

public void enqueue(T newEntry)

{

Node newNode = new Node(newEntry, null);

if (isEmpty())

firstNode = newNode;

else

lastNode.setNextNode(newNode);

lastNode = newNode;

} // end enqueue

Explanation / Answer

public void splice(LinkedQueue<T> secondQueue)
{   
if(isEmpty())
{
firstNode = secondQueue.firstNode;
} else
{
lastNode.next = secondQueue.firstNode;
}   

lastNode = secondQueue.lastNode;
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote