基本操作
push(x) 将x压入队列的末端
pop() 弹出队列的第一个元素(队顶元素),注意此函数并不返回任何值
front() 返回第一个元素(队顶元素)
back() 返回最后被压入的元素(队尾元素)
empty() 当队列为空时,返回true
size() 返回队列的长度
例子
#include<iostream>
#include<queue>
using namespace std;
void PrintQueue(queue<int> &q){
while(!q.empty()){
cout<<q.front()<<endl;
q.pop();
}
}
int main(){
queue<int> q;
q.push(1);
q.push(2);
q.push(3);
PrintQueue(q);
return 0;
}