import java.util.*; public class MyQueue<T> { Stack<Integer> s1,s2; public MyQueue(){ s1 = new Stack<Integer>(); s2 = new Stack<Integer>(); } public int size(){ return s1.size() + s2.size(); } public void push(Integer data){ s1.push(data); } public Integer peek(){ if(!s2.empty()){ return s2.peek(); } while(!s1.empty()){ s2.push(s1.pop()); } return s2.peek(); } public Integer remove(){ if(!s2.empty()){ return s2.pop(); } while(!s1.empty()){ s2.push(s1.pop()); } return s2.pop(); } public static void main(String[] args){ MyQueue<Integer> queue = new MyQueue<Integer>(); queue.push(1); queue.push(2); System.out.println(queue.size()); queue.push(3); queue.push(4); // queue.remove(); System.out.println(queue.size()); queue.push(5); while(queue.size()!= 0){ System.out.println(queue.peek()); queue.remove(); } } }