19: Reversing a Stack

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 static <E> void reverse(Stack<E> stack) {
    Queue<E> queue = new LinkedList<>();
    // TODO
  }

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