這個方法確實時有問題的窥浪,進行不必要的搬移操作
```package jzof_ex;
import java.util.Stack;
/**
*
* @author 11253
*用兩個棧實現(xiàn)隊列耕赘,有一個棧始終會是空的宋税,當push的時候stack2空孝鹊,當pop的時候stack1空
*讓我想到了GC里對于年輕代扭仁,Survior From和to,標記清除復制
*/
public class jzof_9 {
Stack<Integer> stack1 = new Stack<Integer>();
Stack<Integer> stack2 = new Stack<Integer>();
public void push(int node) {
while(!stack2.isEmpty()) {
stack1.push(stack2.pop());
}
stack1.push(node);
}
public int pop() {
while(!stack1.isEmpty()) {
stack2.push(stack1.pop());
}
return stack2.pop();
}
}
```java