原创做品,转载请注明出处:http://www.cnblogs.com/shrimp-can/p/5283520.htmlhtml
1、FIFO队列,即先入先出队列函数
1.队列的声明code
std::deque<int> mydeck (3,100); // deque with 3 elements std::list<int> mylist (2,200); // list with 2 elements std::queue<int> first; // empty queue std::queue<int> second (mydeck); // queue initialized to copy of deque std::queue<int,std::list<int> > third; // empty queue with list as underlying container std::queue<int,std::list<int> > fourth (mylist); std::cout << "size of first: " << first.size() << '\n'; std::cout << "size of second: " << second.size() << '\n'; std::cout << "size of third: " << third.size() << '\n'; std::cout << "size of fourth: " << fourth.size() << '\n';
则结果依次为:0 3 0 2
2.bool empty() consthtm
判断队列是否为空blog
c.empty();队列
3.size_type size() constci
返回队列中元素个数element
c.size()get
4.value_type& front();it
const value_type& front() const;
返回队列中第一个元素,即最后插入到队列中的那个元素
c.front();
5.value_type& back();
const value_type& back() const;
返回队列中最后一个元素,即最早入队的那个元素
c.back();
6.void push (const value_type& val)
插入一个新元素在队尾
c.push(value)
7.void emplace(Args&& args)
插入一个新的元素在队尾
c.emplace(args);
8.void pop()
移除队首元素
c.pop();
9.void swap(queue& x)
交换两个队列的内容
c.swap(d);
10.与stack和vector同样,重载了几个运算符:== != < <= > >=
参考来源:http://www.cplusplus.com/reference/queue/queue/