} intmax_value(){ if (max_q.empty()) return-1; return max_q.front(); } voidpush_back(int value){ while (max_q.size() && max_q.back() < value) max_q.pop_back(); q.push(value); max_q.push_back(value); } intpop_front(){ if (q.empty()) return-1; int t = q.front(); q.pop(); if (t == max_q.front()) max_q.pop_front(); return t; } };
/** * Your MaxQueue object will be instantiated and called as such: * MaxQueue* obj = new MaxQueue(); * int param_1 = obj->max_value(); * obj->push_back(value); * int param_3 = obj->pop_front(); */