SHARE
TWEET

Untitled

a guest Dec 9th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template < typename T > class MinMaxQueue {
  2. public:
  3.     queue < T > Q;
  4.     deque < T > D;
  5.     void PushCos(T cosiek) {
  6.         if (Q.size() == 0) {
  7.             Q.push(cosiek);
  8.             D.push_back(cosiek);
  9.         }
  10.         else {
  11.             Q.push(cosiek);
  12.             while (!D.empty() && D.back() < cosiek) {
  13.                 D.pop_back();
  14.             }
  15.             D.push_back(cosiek);
  16.         }
  17.     }
  18.     void RemoveCos() {
  19.         if (Q.front() == D.front()) {
  20.             Q.pop();
  21.             D.pop_front();
  22.         }
  23.         else {
  24.             Q.pop();
  25.         }
  26.     }
  27.     T GimmeMax() {
  28.         return D.front();
  29.     }
  30. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top