1. stack(栈)
后进先出,不支持迭代器,有push()方法,pop()剔除最顶元素,top()返回最顶端的元素
#include#include #include using namespace std;int main(){ stack s; for(int i=1;i<=10;++i){ s.push(i); } for(int j=0;j<10;++j){ cout< <<" "; s.pop(); } cout<
2. queue队列
先进先出,不支持迭代器,有push()方法,pop()剔除第一个元素,front()返回第一个元素
#include#include #include using namespace std;int main(){ queue q; for(int i=0;i<10;++i){ q.push(i); } for(int i=0;i<10;++i){ cout< <<" "; q.pop(); } cout<
3. deque(双端队列)
支持迭代器,有push_back()方法,跟vector差不多,比vector多了个pop_front,push_front方法,有pop_back(),
back(), front()方法
#include#include #include using namespace std;int main(){ deque q; for(int i=0;i<10;++i){ q.push_back(i); } cout< <