栈实现队列(维护最大值)
package alogrithm;public class MyQueue {private MyStack stackA;private MyStack stackB;public MyQueue(){stackA = new MyStack();stackB = new MyStack();}public int maxValue(int x,int y){return x>y?x:y;}public int max(){return maxValue(stackA.max(), stackB.max());}public void enQueue(int x){stackA.push(x);}public int Dequeue(){if(stackA.isEmpty()){while(!stackB.isEmpty())stackA.push(stackB.pop());}return stackA.pop();}}