C++ queue 和 deque的区别

从使用的角度来说主要差异就是:3d

deque支持push_front、pop_front、push_back、pop_back。code

queue支持push_back、pop_front。blog

----------------------------------------------------------------------------接口

deque是双端队列队列

#include<deque>
 
template<typename T,typename Allocator=std::allocator<T>>class deque;

支持push_front、pop_front、push_back、pop_back等几种操做的。queue是容器适配器,他的声明是模板

#include<queue>
 
template<typename T,typename Container=std::deque<T>>class queue;

类型Container是用来存储元素的,至关因而这个queue的实现。这个queue模板看起来像是包装了这个Container类型,只提供一些特殊的接口,使他看起来想一个queue。class

模板参数Container须要知足顺序容器的条件,并且必须支持front、back、push_back、pop_front操做,标准容器中有deque和list知足。也就是说标准容器中deque和list能够封装成queue。容器