【STL之queue】队列的使用
操作集
q.front();
q.back();
q.push(x);
q.pop();
q.size();
q.empty();
代码
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
queue<int> q;
int main(){
for (int i = 1; i <= 5; i++) q.push(i);
int head, tail;
head = q.front();
tail = q.back();
printf("size=%d\n", int(q.size()));
printf("head=%d tail=%d\n", head, tail);
q.pop();
head = q.front();
tail = q.back();
printf("size=%d\n", int(q.size()));
printf("head=%d tail=%d\n", head, tail);
while (!q.empty()) q.pop();
printf("size=%d\n", int(q.size()));
return 0;
}