2.栈:后进先出(LIFO)
package test.my.chap0302;
import java.util.Stack;
public class QueueWithTwoStack<E> {
private Stack<E> stack1 = new Stack<E>();
private Stack<E> stack2 = new Stack<E>();
public void appendTail(E e){
stack1.push(e);
}
public EdeleteEle() throws Exception{
if(stack2.size()<=0){
while(!stack1.isEmpty()){
stack2.push(stack1.pop());
}
}
if(stack2.size()==0){
throw new Exception("Queue is empty!");
}
return stack2.pop();
}
}