import java.util.*;
//两个æ ç»æä¸ä¸ªéå
//
//æ ¸å¿ææ³
//1ãåå¤ä¸¤ä¸ªæ ï¼
// ä¸ä¸ªç¨äºæ£å¸¸å
¥æ pushStack
// ä¸ä¸ªç¨äºåºæ popStack
//2ãå
¥æ æä½å
¨é¨åå
¥pushStackæ
//3ãåºæ çæ¶åï¼éè¦æ³¨æå¦ä¸ä¸¤ç¹ï¼
// 3.1 妿popStack为空ï¼å°±éè¦ä¸æ¬¡æ§å°pushStackæ çæ°æ®å
¨é¨åºæ ï¼å¹¶åå
¥popStack
// 3.2 å¦åï¼ç´æ¥ä»popStackåºæ
//
public class TwoStackForQueue{
Stack pushStack = new Stack();
Stack popStack = new Stack();
//对æ°å¨æ£å¸¸çéå
Queue queue = new LinkedList();
public void push(int v){
pushStack.push(v);
}
public void pushQueue(int v){
queue.offer(v);
}
public void popQueue(){
queue.poll();
}
public int pop(){
if(!popStack.isEmpty()){
return popStack.pop();
}else{
while(!pushStack.isEmpty()){
popStack.push(pushStack.pop());
}
if(popStack.isEmpty()) return -1;
return popStack.pop();
}
}
public Boolean isEmpty(){
return popStack.isEmpty() && pushStack.isEmpty();
}
public Queue getQueue(){
return queue;
}
public Boolean isTrue(){
int max = 100000;
int optionsCount = 10000;
for (int j=0;j< max;j++ ) {
TwoStackForQueue queue = new TwoStackForQueue();
for (int i=0; i _queue = queue.getQueue();
while(!_queue.isEmpty()){
int v = _queue.poll();
int v1 = queue.pop();
if(v!=v1) return false;
}
if(!queue.isEmpty()) return false;
}
return true;
}
public static void main(String[] args){
TwoStackForQueue queue = new TwoStackForQueue();
System.out.print("æµè¯ç»æï¼"+queue.isTrue());
}
}