Homework 21: Reversing a Queue

Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.


Suppose you had the following code:

public void reverse(Queue queue) {
  Stack stack = new Stack();
  // TODO
}

(2 points) Fill in this method such that that when it returns, the order of the items in the queue is reversed. Do not allocate any new structures (like an array or list); use only the defined queue and stack.