queue 是一种先进先出(first in first out, FIFO)的数据类型,他有两个口,只允许从队尾插入,队头弹出。
- 必须从一个口数据元素入队,另一个口数据元素出队。
- 不能随机存取,不支持遍历
queue 构造函数
1
2
| queue<T> queT;//queue 采用模板类实现,queue 对象的默认构造形式:
queue(const queue &que);//拷贝构造函数
|
queue 存取、插入和删除操作
1
2
3
4
| push(elem);//往队尾添加元素
pop();//从队头移除第一个元素
back();//返回最后一个元素
front();//返回第一个元素
|
queue 赋值操作
1
| queue& operator=(const queue &que);//重载等号操作符
|
queue 大小操作
1
2
| empty();//判断队列是否为空
size();//返回队列的大小
|