This article modifies the self http://www.cnblogs.com/hdk1993/p/5809180.html
1. Use queue to declare header file # include <queue>
2, the queue template class requires two template parameters, one is the element type, a container type, the element type is necessary, the container type is optional, the default is the Deque type.
3, the basic operation of the queue is:
Queue, as in example: Que.push (x); Connect X to the end of the queue.
Out of the team, as in Example: Que.pop (); The first element of the popup queue, note that the value of the popup element is not returned.
Access the first element of the team, such as: Que.front (), which is the first element to be pressed into the queue.
Access the tail element, such as: Que.back (), which is the element that was last pressed into the queue.
Determine if the queue is empty, as in example: Que.empty (), returns True when the queue is empty.
Access to the number of elements in the queue, as in example: Que.size ()
Code chestnut:
#include <iostream>#include<queue>using namespacestd;intMain () {queue<int>que; for(intI=0;i<Ten; i++) {Que.push (i); } if(!Que.empty ()) {cout<<"the queue is not empty. "<<Endl; } cout<<"the elements at the end of the team are:"; cout<<que.back () <<Endl; cout<<"To traverse a queue:"<<Endl; while(Que.size ()) {cout<<que.front () <<Endl; Que.pop (); } if(Que.empty ()) {cout<<"The elements are all ejected and the queue is empty. "<<Endl; } return 0;}
Output:
The queue is not empty.
The elements at the end of the team are: 9
To traverse a queue:
0
1
2
3
4
5
6
7
8
9
The elements are all ejected and the queue is empty.
C + + STL Learning queue