package com.fishercoder.solutions;

import java.util.Stack;
/**Implement the following operations of a queue using stacks.

 push(x) -- Push element x to the back of queue.
 pop() -- Removes the element from in front of queue.
 peek() -- Get the front element.
 empty() -- Return whether the queue is empty.
 Notes:
 You must use only standard operations of a stack -- which means only push to top, peek/pop from top, size, and is empty operations are valid.
 Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.
 You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).*/
public class _232 {

    class MyQueue {

        Stack<Integer> input = new Stack();
        Stack<Integer> output = new Stack();

        // Push element x to the back of queue.
        public void push(int x) {
            input.push(x);
        }

        // Removes the element from in front of queue.
        public int pop() {
            peek();
            return output.pop();
        }

        // Get the front element.
        public int peek() {
            if (output.isEmpty()) {
                while (!input.isEmpty()) {
                    output.push(input.pop());
                }
            }
            return output.peek();
        }

        // Return whether the queue is empty.
        public boolean empty() {
            return input.isEmpty() && output.isEmpty();
        }
    }
}

@@ -56,16 +56,60 @@
 ack;%0A/**
+%0A * 232. Implement Queue using Stacks%0A *%0A * 
 Implemen
@@ -345,16 +345,17 @@
  empty.%0A
+%0A
  Notes:%0A
@@ -811,16 +811,18 @@
  queue).
+%0A 
 */%0Apubli
@@ -833,24 +833,64 @@
 ass _232 %7B%0A%0A
+    public static class Solution1 %7B%0A    
     class My
@@ -894,24 +894,28 @@
  MyQueue %7B%0A%0A
+    
         Stac
@@ -946,32 +946,36 @@
 tack();%0A        
+ 
+   
 Stack%3CInteger%3E o
@@ -996,16 +996,20 @@
 ack();%0A%0A
+    
         
@@ -1052,24 +1052,28 @@
 ue.%0A        
+  
+  
 public void 
@@ -1098,16 +1098,20 @@
         
+    
 input.pu
@@ -1117,35 +1117,43 @@
 ush(x);%0A        
+   
+ 
 %7D%0A%0A
+    
         // Remov
@@ -1183,32 +1183,36 @@
 front of queue.%0A
+    
         public i
@@ -1234,24 +1234,28 @@
         
+    
 peek();%0A
         
@@ -1238,32 +1238,36 @@
         peek();%0A
+    
             retu
@@ -1283,35 +1283,43 @@
 .pop();%0A        
+  
+  
 %7D%0A%0A
+    
         // Get t
@@ -1336,32 +1336,36 @@
 lement.%0A        
+   
+ 
 public int peek(
@@ -1364,24 +1364,28 @@
 nt peek() %7B%0A
+    
             
@@ -1400,32 +1400,36 @@
 ut.isEmpty()) %7B%0A
+    
                 
@@ -1475,16 +1475,20 @@
         
+    
 output.p
@@ -1513,32 +1513,36 @@
                 
+    
 %7D%0A            %7D%0A
@@ -1531,34 +1531,42 @@
   %7D%0A            
+ 
-%7D%0A
+   %7D%0A    
             retu
@@ -1583,35 +1583,43 @@
 peek();%0A        
+   
+ 
 %7D%0A%0A
+    
         // Retur
@@ -1648,16 +1648,20 @@
  empty.%0A
+    
         
@@ -1693,24 +1693,28 @@
             
+    
 return input
@@ -1741,24 +1741,38 @@
 .isEmpty();%0A
+            %7D%0A
         %7D%0A  
@@ -1777,8 +1777,9 @@
     %7D%0A%7D%0A
+%0A

refactor 232