package com.fishercoder.solutions;

import java.util.LinkedList;
import java.util.Queue;
/**Implement the following operations of a stack using queues.

 push(x) -- Push element x onto stack.
 pop() -- Removes the element on top of the stack.
 top() -- Get the top element.
 empty() -- Return whether the stack is empty.
 Notes:
 You must use only standard operations of a queue -- which means only push to back, peek/pop from front, size, and is empty operations are valid.
 Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue.
 You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack).
 Update (2015-06-11):
 The class name of the Java function had been updated to MyStack instead of Stack.*/

public class _225 {
    class MyStack {

        Queue<Integer> q = new LinkedList();

        // Push element x onto stack.
        public void push(int x) {
            q.offer(x);
            for (int i = 1; i < q.size(); i++) {
                q.offer(q.remove());
            }
        }

        // Removes the element on top of the stack.
        public void pop() {
            q.poll();
        }

        // Get the top element.
        public int top() {
            return q.peek();
        }

        // Return whether the stack is empty.
        public boolean empty() {
            return q.isEmpty();
        }
    }
}

@@ -85,16 +85,60 @@
 eue;%0A/**
+%0A * 225. Implement Stack using Queues%0A *%0A * 
 Implemen
@@ -358,16 +358,17 @@
  empty.%0A
+%0A
  Notes:%0A
@@ -955,16 +955,57 @@
  _225 %7B%0A
+%0A    public static class Solution1 %7B%0A    
     clas
@@ -1025,16 +1025,20 @@
         
+ 
+   
 Queue%3CIn
@@ -1075,16 +1075,20 @@
         
+    
 // Push 
@@ -1109,32 +1109,36 @@
  stack.%0A        
+ 
+   
 public void push
@@ -1151,32 +1151,36 @@
 ) %7B%0A            
+    
 q.offer(x);%0A    
@@ -1187,16 +1187,20 @@
         
+ 
+   
 for (int
@@ -1236,32 +1236,36 @@
                 
+    
 q.offer(q.remove
@@ -1285,18 +1285,25 @@
     
+ 
-%7D%0A
+   %7D%0A   
         
 %7D%0A%0A 
@@ -1290,35 +1290,40 @@
    %7D%0A           
+ 
 %7D%0A%0A
+    
         // Remov
@@ -1358,32 +1358,36 @@
  stack.%0A        
+    
 public void pop(
@@ -1402,16 +1402,20 @@
         
+  
+  
 q.poll()
@@ -1416,32 +1416,36 @@
 poll();%0A        
+    
 %7D%0A%0A        // Ge
@@ -1439,16 +1439,20 @@
         
+  
+  
 // Get t
@@ -1471,24 +1471,28 @@
 nt.%0A        
+    
 public int t
@@ -1502,32 +1502,36 @@
 ) %7B%0A            
+  
+  
 return q.peek();
@@ -1531,32 +1531,36 @@
 peek();%0A        
+    
 %7D%0A%0A        // Re
@@ -1550,24 +1550,28 @@
  %7D%0A%0A        
+  
+  
 // Return wh
@@ -1600,24 +1600,28 @@
 ty.%0A        
+    
 public boole
@@ -1637,32 +1637,36 @@
 ) %7B%0A            
+  
+  
 return q.isEmpty
@@ -1665,24 +1665,38 @@
 .isEmpty();%0A
+            %7D%0A
         %7D%0A  

refactor 225