标签:cto queue void 入队 printf 元素 例子 empty main
#include <queue>
queue < int > q;
priority_queue < int, vector< int >, greater< int > > q; //递增
priority_queue < int, vector< int >, less< int > >q; //递减
#include <queue>
#include <cstdio>
using namespace std;
queue < int > q1;
priority_queue < int, vector< int >, greater< int > > q2;
priority_queue < int, vector< int >, less< int > >q3;
int main()
{
q1.push(2); q1.push(1); q1.push(3); q1.push(5); q1.push(4);
q2.push(2); q2.push(1); q2.push(3); q2.push(5); q2.push(4);
q3.push(2); q3.push(1); q3.push(3); q3.push(5); q3.push(4);
printf("q1.size = %d\nq1.top = %d\n", q1.size(), q1.front());
printf("q2.size = %d\nq2.top = %d\n", q2.size(), q2.top());
printf("q3.size = %d\nq3.top = %d\n", q3.size(), q3.top());
printf("q1:");
while (!q1.empty())
{
printf("%d ", q1.front());
q1.pop();
}
puts("");
printf("q2:");
while (!q2.empty())
{
printf("%d ", q2.top());
q2.pop();
}
puts("");
printf("q3:");
while (!q3.empty())
{
printf("%d ", q3.top());
q3.pop();
}
puts("");
}
标签:cto queue void 入队 printf 元素 例子 empty main
原文地址:https://www.cnblogs.com/xuyixuan/p/9440977.html