目录
1.Queue容器概述
2.queue对象的默认构造
3.queue 对象的带参构造
4.queue的push()与pop()方法
5.queue对象的拷贝构造与赋值
6.queue的数据存取
7.queue的大小
1.Queue容器概述
queue是队列容器,是一种“先进先出”的容器。
1.默认情况下queue是利用deque容器实现的一种容器。
2.它只允许在队列的前端(front)进行删除操作,而在队列的后端(back)进行插入操作
3.#include
2.queue对象的默认构造
queue采用模板类实现,queue对象的默认构造形式:queue queT; 如:
queue queueInt; //一个存放int的queue容器。
queue queueFloat; //一个存放float的queue容器。
queue queueString; //一个存放string的queue容器。
...
注意: 尖括号内还可以设置指针类型或自定义类型。
3.queue 对象的带参构造
queue> queueList; //内部使用list 来存储队列元素的queue 容器.
错误: queue> queueList; //内部不能使用vector来存储队列元素(要有支持pop_front的才可以)
queue是队列容器,是一种“先进先出”的容器。
1.默认情况下queue是利用deque容器实现的一种容器。
2.它只允许在队列的前端(front)进行删除操作,而在队列的后端(back)进行插入操作
3.#include
queue采用模板类实现,queue对象的默认构造形式:queue
queT; 如: queue
queueInt; //一个存放int的queue容器。 queue
queueFloat; //一个存放float的queue容器。 queue
queueString; //一个存放string的queue容器。 ...
注意: 尖括号内还可以设置指针类型或自定义类型。
3.queue 对象的带参构造
queue> queueList; //内部使用list 来存储队列元素的queue 容器.
错误: queue> queueList; //内部不能使用vector来存储队列元素(要有支持pop_front的才可以)
queue
错误: queue
4.queue的push()与pop()方法
1.queue.push(elem); //往队尾添加元素
2.queue.pop(); //从队头处移除队首元素
queue queueInt;
queueInt.push(1);
queueInt.push(2);
queueInt.push(3);
queueInt.push(4);
queueInt.pop();
queueInt.pop();
此时queueInt存放的元素是3, 4
5.queue对象的拷贝构造与赋值
1.queue(const queue &que); //拷贝构造函数
2.queue& operator=(const queue &que); //重载等号操作符
queue queIntA;
queIntA.push(1);
queIntA.push(2);
queIntA.push(3);
queIntA.push(4);
queIntA.push(5);
queue queIntB(queIntA); //拷贝构造
queue queIntC;
queIntC = queIntA; //赋值
6.queue的数据存取
1.queue.back(); //返回最后一个元素
2.queue.front(); //返回第一个元素
queue queIntA;
queIntA.push(1);
queIntA.push(2);
queIntA.push(3);
queIntA.push(4);
queIntA.push(5);
int iFront = queIntA.front(); //1
int iBack = queIntA.back(); //5
queIntA.front() = 66; //66
queIntA.back() = 88; //88
7.queue的大小
1.queue.empty(); //判断队列是否为空
2.queue.size(); //返回队列的大小
queue queIntA;
queIntA.push(1);
queIntA.push(2);
queIntA.push(3);
queIntA.push(4);
queIntA.push(5);
if (!queIntA.empty()){
int iSize = queIntA.size(); //iSize = 5
}
1.queue.push(elem); //往队尾添加元素
2.queue.pop(); //从队头处移除队首元素
1.queue(const queue &que); //拷贝构造函数
2.queue& operator=(const queue &que); //重载等号操作符
queuequeIntA; queIntA.push(1); queIntA.push(2); queIntA.push(3); queIntA.push(4); queIntA.push(5); queue queIntB(queIntA); //拷贝构造 queue queIntC; queIntC = queIntA; //赋值
6.queue的数据存取
1.queue.back(); //返回最后一个元素
2.queue.front(); //返回第一个元素
queue queIntA;
queIntA.push(1);
queIntA.push(2);
queIntA.push(3);
queIntA.push(4);
queIntA.push(5);
int iFront = queIntA.front(); //1
int iBack = queIntA.back(); //5
queIntA.front() = 66; //66
queIntA.back() = 88; //88
7.queue的大小
1.queue.empty(); //判断队列是否为空
2.queue.size(); //返回队列的大小
queue queIntA;
queIntA.push(1);
queIntA.push(2);
queIntA.push(3);
queIntA.push(4);
queIntA.push(5);
if (!queIntA.empty()){
int iSize = queIntA.size(); //iSize = 5
}
1.queue.back(); //返回最后一个元素
2.queue.front(); //返回第一个元素
1.queue.empty(); //判断队列是否为空
2.queue.size(); //返回队列的大小
queuequeIntA; queIntA.push(1); queIntA.push(2); queIntA.push(3); queIntA.push(4); queIntA.push(5); if (!queIntA.empty()){ int iSize = queIntA.size(); //iSize = 5 }



