C++ STL queue
来源:互联网 发布:淘宝店铺类目是什么 编辑:程序博客网 时间:2024/04/29 22:54
template <class T, class Container = deque<T> > class queue;
FIFO queue
queues are a type of container adaptor, specifically designed to operate in a FIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.queues are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed into the "back" of the specific container and popped from its "front".
The underlying container may be one of the standard container class template or some other specifically designed container class. This underlying container shall support at least the following operations:
- front
- back
- push_back
- pop_front
The standard container classes deque and list fulfill these requirements. By default, if no container class is specified for a particular queue class instantiation, the standard container deque is used.
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
queue<string> q;
q.push("These ");
q.push("are ");
q.push("more than ");
cout<<q.front();
q.pop();
cout<<q.front();
q.pop();
q.push("four ");
q.push("words!");
q.pop();
cout<<q.front();
q.pop();
cout<<q.front()<<endl;
q.pop();
cout<<"number of elements in the queue:"<<q.size()<<endl;
return 1;
}
#include <queue>
#include <string>
using namespace std;
int main(){
queue<string> q;
q.push("These ");
q.push("are ");
q.push("more than ");
cout<<q.front();
q.pop();
cout<<q.front();
q.pop();
q.push("four ");
q.push("words!");
q.pop();
cout<<q.front();
q.pop();
cout<<q.front()<<endl;
q.pop();
cout<<"number of elements in the queue:"<<q.size()<<endl;
return 1;
}
编译后输出:
These are four words!
number of elements in the queue:0
number of elements in the queue:0
0 0
- 【C++】STL--QUEUE
- C++STL之queue用法
- 如何使用queue? (C/C++) (STL)
- C++STL练习<queue> <set>容器使用
- C++STL之queue队列容器
- c++stl的queue和priority_queue
- STL--Queue
- STL QUEUE
- stl-queue
- stl queue
- stl queue
- stl queue
- STL queue
- STL queue
- STL-queue
- STL--queue
- STL queue
- STL queue
- runtime exec
- Android中自定义Adapter的基本原理
- spring MVC配置详解
- Android之自定义Adapter的ListView
- Linux 下c语言ftp服务器简单实现
- C++ STL queue
- android 源码下载
- SeedCoder2014热身题10:解答
- k-折交叉验证(k-fold crossValidation)
- Codeforces Round #240 (Div. 2)(前三题解题报告)
- 【转载】UML类图与类的关系详解
- POJ 3106 Flip and Turn
- linux中fork()函数详解
- ftp报错 200 port command successful. consider using pasv 425 failed to establish connection