previous | start | next

1.3.6

1.3.6 What does the following code fragment do to the queue q?

Stack<String> stack = new Stack<String>();

while (!q.isEmpty()) {
  stack.push(q.dequeue());
}

while (!stack.isEmpty()) {
  q.enqueue(stack.pop());
}

For example, suppose the elements in the queue are:

(front) "A" "B" "C" "D" "E" (back)
   


previous | start | next