classMyQueue{private LinkedList<Integer> stack1;private LinkedList<Integer> stack2;/** Initialize your data structure here. */publicMyQueue(){
stack1 =newLinkedList<Integer>();
stack2 =newLinkedList<Integer>();}/** Push element x to the back of queue. */publicvoidpush(int x){
stack1.push(x);}privatevoid trans (){for(int i=stack1.size();i>0;i--){
stack2.push(stack1.pop());}}/** Removes the element from in front of queue and returns that element. */publicintpop(){if(stack2.size()==0)trans();return stack2.pop();}/** Get the front element. */publicintpeek(){if(stack2.size()==0)trans();return stack2.peek();}/** Returns whether the queue is empty. */publicbooleanempty(){return stack1.size()==0&& stack2.size()==0;}}