// // Created by Scheaven on 2020/6/8. // #ifndef _QUEUE_UTIL_H #define _QUEUE_UTIL_H #include "stack_util.hpp" using namespace std; template class MaxQueue { private: MaxStack stackA; MaxStack stackB; public: MaxQueue(){}; ~MaxQueue(){}; void push(T ele) { stackA.push(ele); }; void pop() { if(stackB.isEmpty()) { // if(stackA.isEmpty()) // { // return ; // } while (!stackA.isEmpty()) { stackB.push(stackA.top()); stackA.pop(); } } stackB.pop(); }; T front() { if(stackB.isEmpty()) { // if(stackA.isEmpty()) // { // return ; // } while (!stackA.isEmpty()) { stackB.push(stackA.top()); stackA.pop(); } } return stackB.top(); }; T max() { if(!stackA.isEmpty()&&!stackB.isEmpty()) { return stackA.maxItem()>stackB.maxItem()?stackA.maxItem():stackB.maxItem(); } else if(!stackA.isEmpty()&&stackB.isEmpty()) { return stackA.maxItem(); } else { return stackB.maxItem(); } }; int size() { return stackA.size()+stackB.size(); } bool isEmpty() { return stackA.isEmpty()&&stackB.isEmpty(); }; }; template class MinQueue { private: MinStack stackA; MinStack stackB; public: MinQueue(){}; ~MinQueue(){}; void push(T ele) { stackA.push(ele); }; void pop() { if(stackB.isEmpty()) { // if(stackA.isEmpty()) // { // return ; // } while (!stackA.isEmpty()) { stackB.push(stackA.top()); stackA.pop(); } } stackB.pop(); }; T front() { if(stackB.isEmpty()) { // if(stackA.isEmpty()) // { // return ; // } while (!stackA.isEmpty()) { stackB.push(stackA.top()); stackA.pop(); } } return stackB.top(); }; T min() { if(!stackA.isEmpty()&&!stackB.isEmpty()) { return stackA.minItem()