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;
}

  

上一篇:C++ 自定义订单号


下一篇:吴裕雄--天生自然Linux操作系统:Linux 磁盘管理