package co.eipi.java.algo.queue;

import co.eipi.java.algo.stack.Stack;

public class QueueOfStacks<T> implements IQueue<T>
{
    private Stack<T> mainStack = new Stack<T>();
    private Stack<T> reverseStack = new Stack<T>();
    
    @Override
    public void enqueue(T data)
    {
	mainStack.push(data);
    }
    
    private void reorg()
    {
	if (reverseStack.isEmpty())
	{
	    while(!mainStack.isEmpty())
	    {
		reverseStack.push(mainStack.pop());
	    }
	}
    }
    
    @Override
    public T dequeue()
    {
	reorg();
	return reverseStack.pop();
    }
    @Override
    public T peek()
    {
	reorg();
	return reverseStack.peek();
    }
}

@@ -123,32 +123,38 @@
 %3E%0A%7B%0A    private 
+final 
 Stack%3CT%3E mainSta
@@ -186,16 +186,22 @@
 private 
+final 
 Stack%3CT%3E

use final