栈实现队列
因为这个是自己写的,可能很麻烦,不过特别好懂
import java.util.Stack; public class 队列实现栈 { private static Stack<Object> stackin = new Stack<>(); private static Stack<Object> stackout = new Stack<>(); public void push(int x){ stackin.push(x); } public Object pop(){ for (int i = 0; i < stackin.size(); i++) { stackout.push(stackin.pop()); } Object i = stackout.pop(); for (int j = 0; j < stackout.size(); j++) { stackin.push(stackout.pop()); } return i; } public Boolean empty(){ return stackout.empty()&&stackin.empty(); } }