C++ Queues
The C++ Queue is a container adapter that gives the programmer a FIFO (first-in, first-out) data structure.
Display all entries for C++ Queues on one page, or view entries individually:
Queue constructor | construct a new queue |
back | returns a reference to last element of a queue |
empty | true if the queue has no elements |
front | returns a reference to the first element of a queue |
pop | removes the first element of a queue |
push | adds an element to the end of the queue |
size | returns the number of items in the queue |
1#include<iostream>
2#include<queue>
3#include<algorithm>
4using namespace std;
5int main()
6{
7 //队列,first_in ,first_out,不提供迭代器,不提供走访功能
8 int i;
9 queue<int>q;
10 for(i=0;i<5;i++)q.push(i);
11 while(q.size()){
12 cout<<q.front();
13 q.pop();
14 }
15 return 0;
16}
17
2#include<queue>
3#include<algorithm>
4using namespace std;
5int main()
6{
7 //队列,first_in ,first_out,不提供迭代器,不提供走访功能
8 int i;
9 queue<int>q;
10 for(i=0;i<5;i++)q.push(i);
11 while(q.size()){
12 cout<<q.front();
13 q.pop();
14 }
15 return 0;
16}
17