queue STL

//queue STL
//queue is just a container adaptor, which is a class that use other container.
//just like stack
q1.push(x)     //push x into the queue
q1.pop()        //pop the first element in the queue
q1.front()       //return the first element in the queue
q1.back()        //return the last element in the queue
q1.empty()      
q1.size()

//C++11
q1.emplace(x)    //add a new element at the end of the queue, after its current last element 

//the differences between emplace and push
//though they are both the functions to add elements in the queue
//if you use emplace ,you will not make a new class.
//Let's see a example
struct node
{
	int x, y;

	node(int a, int b) :x(a), y(b){}
};

int main()
{
	queue<node>q1,q2;
	q1.emplace(1, 2);
	q2.push(node(1, 2));

	cout << q1.front().x << endl;

	return 0;
}  

  

posted @ 2016-10-13 15:38  KennyRom  阅读(155)  评论(0编辑  收藏  举报