STL学习(五)queue容器学习
2014-07-17 15:04
120 查看
queue 是在一端存数据,在另一端取数据。数据是先进先出(first in first out,FIFO)。在STL中,单向队列也是以别的容器作为底部结构,再将接口改变,使之符合单向队列的特性。默认用deque实现。常用函数为 front()、back()、push()、pop()、empty()、size()
#include <queue> #include <list> #include <iostream> using namespace std; int main() { queue<int> q1; /*default use deque*/ queue<int,list<int> > q2; queue<int,vector<int> > q3; q3.push(1); //q3.pop(1); /*err: vector not support pop_front()*/ int i=1; for(i=10;i<20;i++) { q1.push(i); q2.push(i); } cout<< "q1.size is " << q1.size() << endl; cout<< "q1.front is " << q1.front() << " " << "q1.back is " << q1.back() << endl; while(!q1.empty()) { cout <<q1.front()<< " "; q1.pop(); } cout<<endl; cout<< "q2.size is " << q2.size() << endl; cout<< "q2.front is " << q2.front() << " " << "q2.back is " << q2.back() << endl; while(!q2.empty()) { cout <<q2.front()<< " "; q2.pop(); } cout<<endl; return 0; } ~
相关文章推荐
- STL学习笔记13— —特殊容器priority_queue
- STL学习笔记— —特殊容器priority_queue
- C++ STL--queue队列容器学习笔记
- STL学习笔记12— —特殊容器queue
- C++ STL容器的学习使用(vector、queue、list、set、map)
- STL学习——STL中的序列式容器及适配器总结(vector、list、deque、stack、queue)
- STL学习笔记— —特殊容器queue
- 标准模板库(STL)学习探究之Queue容器
- STL学习系列五:Queue容器
- stl基本容器学习1
- C++ STL学习笔记十二 hash_map映照容器
- [C++再学习系列] 函数声明与STL容器构造
- [C++再学习系列] STL容器的存储结构
- 标准模板库(STL)学习探究之MultiSet容器
- C++ STL学习笔记三 deque双端队列容器
- stl基本容器学习——函数对象
- 标准模板库(STL)学习之List容器___4
- 标准模板库(STL)学习指南之List容器
- 标准模板库(STL)学习探究之List容器
- 标准模板库(STL)学习探究之vector容器