/**两个队列生成一个栈 * *思路:队列1和队列2在任意时刻至少有一个为空,即如果有元素,所有元素只能在一个队列中。 *当有元素需要插入时,将元素插入到空队列中,并将另一非空队列的所有元素全部转移到该队列 *中。于是,插入的元素添加到了队列的最前面。 */ public class Stack { Queue queue1 = new Queue(); Queue queue2 = new Queue();
//判断非空 public boolean isEmpty(){ return queue1.isEmpty() && queue2.isEmpty(); }