Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 452 Bytes

File metadata and controls

33 lines (23 loc) · 452 Bytes
title Algorithm4 Java Solution 1.3.06
date 2019-07-04 05:47:10 +0800
draft false
tags
JAVA
categories
TECH
archives

1.3.06

Problem:

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());

Solution:

reverse the elements order in q.

Reference: