class MaxQueue {
LinkedList<Integer> deque1,deque2;
public MaxQueue() {
deque1=new LinkedList<>();
deque2=new LinkedList<>();
}
public int max_value() {
if(deque2.isEmpty()) return -1;
else return deque2.getFirst();
}
public void push_back(int value) {
while(!deque2.isEmpty()&&value>deque2.getLast()){
deque2.removeLast();
}
deque1.addLast(value);
deque2.addLast(value);
}
public int pop_front() {
if(deque1.isEmpty()) return -1;
if((int)deque1.getFirst()==deque2.getFirst()) deque2.removeFirst();
return deque1.removeFirst();
}
}
12-19
433
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-13
1572
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)