如果有人问起了手写队列和STL的差别

Creeper_LKF

2018-01-09 22:16:16

Personal

如下图: 前者手写双端队列,后者std::deque,同开O2 ![](https://cdn.luogu.com.cn/upload/pic/12956.png) 然后不开O2,std::deque已经挂了 ![](https://cdn.luogu.com.cn/upload/pic/12957.png) 然后手写双端队列活了下来 ![](https://cdn.luogu.com.cn/upload/pic/12958.png) 此处手写双端队列考虑用途所以并未进行下标处理 手写双端队列代码如下: struct Q{ private: int s, t; int q[MAXM]; public: ```cpp Q(){ s = MAXN , t = s - 1; } inline void clear(){ s = MAXN, t = s - 1; } inline bool empty(){ return s > t; } inline int front(){ return q[s]; } inline int back(){ return q[t]; } inline void pop_front(){ s++; } inline void pop_back(){ t--; } inline void push_back(int tar){ q[++t] = tar; } inline void push_front(int tar){ q[--s] = tar; } }mession; ```