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

Question 2.1 ReverseQueue The method reverseQueue is a class method of StacksAnd

ID: 3707913 • Letter: Q

Question

Question 2.1 ReverseQueue The method reverseQueue is a class method of StacksAndQucues that takes a Queue of String instances as input parameter. After calling that method, the elements in the queue should be reversed. For example, if the following queue is passed to reverseQueue (front)->a, b, c, d, e-(rear) after the call, the queue should contain (front) -> [e, d, c, b, a(rear) Provide your implementation of reverseQueue in the box below. public class StacksAndQucues I1 implementation of method reverseQueue reverseQueue(ueuetring> queue)l if (queue tmp = while ( Imp while( queue

Explanation / Answer

import java.util.Queue; import java.util.Stack; public class StacksAndQueues { public void reverseQueue(Queue queue) { if(queue.isEmpty()) { return; } Stack tmp = new Stack(); while (!queue.isEmpty()) { tmp.push(queue.poll()); } while (!tmp.empty()) { queue.add(tmp.pop()); } } }
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