/*
back()返回一个引用,指向队列的最后一个元素。
empty()函数返回真(true)如果队列为空,否则返回假(false)。
front()返回队列第一个元素的引用。
pop()函数删除队列的一个元素
push() 在末尾加入一个元素
size() 返回队列中元素的个数
*/
#include <queue>
#include <iostream>
using namespace std;
int main()
{
queue<int> q;
for (int i = 0; i < 10; i++)
{
q.push(i);
}
if (q.empty())
{
cout << " queue is empty" << endl;
return -1;
}
int n = q.size();
cout << "队列长度:"<<n << endl;
cout <<"队列的最后一个元素"<< q.back() << endl;
for (int j = 0; j < n; j++)
{
cout<<q.front()<<endl;
q.pop();
}
system("pause");
return 1;
}
运行结果:
参考:
https://blog.csdn.net/qq_41785863/article/details/81630386