Answered step by step
Verified Expert Solution
Question
1 Approved Answer
It needs to be Eclipse IDE Java Implement a method concatenate in class LinkedQueue. This method should take all the elements of a queue sourceQ
It needs to be Eclipse IDE Java
Implement a method concatenate in class LinkedQueue. This method should take all the elements of a queue sourceQ and append them to the end of another queue targetQ. The operation should result in sourceQ being an empty queue. Test this method in the main method of LinkedQueue.
public class LinkedQueue implements Queue
The primary storage for elements of the queue
private SinglyLinkedList list new SinglyLinkedList; an empty list
Constructs an initially empty queue.
public LinkedQueue new queue relies on the initially empty list
Returns the number of elements in the queue.
@return number of elements in the queue
@Override
public int size return list.size;
Tests whether the queue is empty.
@return true if the queue is empty, false otherwise
@Override
public boolean isEmpty return list.isEmpty;
Inserts an element at the rear of the queue.
@param element the element to be inserted
@Override
public void enqueueE element list.addLastelement;
Returns, but does not remove, the first element of the queue.
@return the first element of the queue or null if empty
@Override
public E first return list.first;
Removes and returns the first element of the queue.
@return element removed or null if empty
@Override
public E dequeue return list.removeFirst;
Produces a string representation of the contents of the queue.
from front to back This exists for debugging purposes only.
public String toString
return list.toString;
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