submit a .java file (for source code) and a .txt file for program output. If the
ID: 3872021 • Letter: S
Question
submit a .java file (for source code) and a .txt file for program output. If the problem involves other questions, submit a separate .txt file to answer the question.
Part 1 - In this problem, we will add new methods to the class ArrayQueue
Suppose that we want to add a method to a class of queues that will splice two queues together. This method adds to the end of a queue all items that are in a second queue (making the second queue empty). The header of the method could be as follows:
public void splice(QueueInterface<T> anotherQueue)
Write this method for the class ArrayQueue
Explanation / Answer
Hopefully, this could work. If not, please share the QueueInterface code so that I could do the required modifications for you:
public void splice(QueueInterface<T> anotherQueue)
{
while(!anotherQueue.empty())
{
T temp = anotherQueue.peek(); //Copy the element from another queue to temp.
anotherQueue.delete(); //Remove the front element from another queue.
this.insert(temp); //Add it to the end of the queue.
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.