标签:style blog http color os strong io for
由小到大
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main()
{
priority_queue < int, vector<int> , greater<int> > q;
q.push(3);
q.push(2);
q.push(1);
q.push(7);
while ( !q.empty())
{
cout<<q.top()<<endl;
q.pop();
}
return 0;
}
//由大到小
#include <iostream>
#include <queue>
using namespace std;
int main()
{
priority_queue <int> q;
q.push(3);
q.push(2);
q.push(1);
q.push(7);
while ( !q.empty())
{
cout<<q.top()<<endl;
q.pop();
}
return 0;
}
************************************************************************************************
#include <iostream>
#include <queue>
using namespace std;
int main()
{
priority_queue<int> q;
for(int i = 1;i <= 5;i++)
{
q.push(i);
}
for(int i = 0;i < 5;i++)
{
cout<<q.top()<<endl;
q.pop();
}
return 0;
}
************************************************************************************************************************
#include <iostream>
#include <queue>
using namespace std;
int main()
{
priority_queue<int> q;
int i;
while (cin>>i)
q.push(i);
cout<<q.top()<<endl;
q.pop();
return 0;
}
Priority Queues,布布扣,bubuko.com
标签:style blog http color os strong io for
原文地址:http://www.cnblogs.com/2014acm/p/3876657.html