c++近容器priority_queue (堆),在生成一个对象时,如何在参数列表里显示调用greater降序(默认less)?
#include<iostream>#include<queue>#include<functional>usingnamespacestd;intmain(){prio...
#include<iostream>
#include<queue>
#include<functional>
using namespace std;
int main()
{
priority_queue<int> p;//这里如何调用greater,求解答。
priority_queue<int> q;
for (int i = 0; i < 5; i++)
{
p.push(i);
}
for (double i = 5; i > 0; i--)
{
q.push(i);
}
while (!p.empty())
{
cout << p.top()<<" ";
p.pop();
}
cout << endl;
while (!q.empty())
{
cout << q.top() << " ";
q.pop();
}
cout << endl;
getchar();
} 展开
#include<queue>
#include<functional>
using namespace std;
int main()
{
priority_queue<int> p;//这里如何调用greater,求解答。
priority_queue<int> q;
for (int i = 0; i < 5; i++)
{
p.push(i);
}
for (double i = 5; i > 0; i--)
{
q.push(i);
}
while (!p.empty())
{
cout << p.top()<<" ";
p.pop();
}
cout << endl;
while (!q.empty())
{
cout << q.top() << " ";
q.pop();
}
cout << endl;
getchar();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询