001package algs13;
002import stdlib.*;
003public class XReverseQueue {
004        public static void main(String[] args) {
005                Trace.drawStepsOfMethod ("main");
006                Trace.run ();
007                Queue<String> q = new Queue<> ();
008                q.enqueue ("a");
009                q.enqueue ("b");
010                q.enqueue ("c");
011                q.enqueue ("d");
012                Stack<String> stack = new Stack<>();
013
014                while (!q.isEmpty())
015                        stack.push(q.dequeue());
016                while (!stack.isEmpty())
017                        q.enqueue(stack.pop());
018                
019                // another version with temporaries:
020//              while (!q.isEmpty()) {
021//                      String x = q.dequeue ();
022//                      stack.push(x);
023//              }
024//              while (!stack.isEmpty()) {
025//                      String x = stack.pop ();
026//                      q.enqueue(x);
027//              }
028        }
029}