#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#define INF 123123123
#define MAX_INDEX 100005
using namespace std;
struct node
{
double a;
string name;
bool operator > (const node &other) const
{
if ((a > other.a))
{
return true;
}
return false;
}
bool operator < (const node &other) const
{
if ((a < other.a))
{
return true;
}
return false;
}
};
int main()
{
priority_queue<node,vector<node>,greater<node> >q;
//注意:这里使用了greater的话,那node结构体里必须重载了>比较符!
//如果没有使用greater,那就是小根堆,那node里必须重载<比较符!
node temp;
temp.name = "s3";
temp.a = 92.78;
q.push(temp);
temp.name = "s2";
temp.a = 91.66;
q.push(temp);
temp.name = "s1";
temp.a = 91.78;
q.push(temp);
temp.name = "s4";
temp.a = 91.41;
q.push(temp);
while(!q.empty())
{
node temp1 = q.top();
q.pop();
cout << temp1.name << " = " << temp1.a << endl;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#define INF 123123123
#define MAX_INDEX 100005
using namespace std;
struct node
{
double a;
string name;
bool operator > (const node &other) const
{
if ((a > other.a))
{
return true;
}
return false;
}
bool operator < (const node &other) const
{
if ((a < other.a))
{
return true;
}
return false;
}
};
int main()
{
priority_queue<node,vector<node>,greater<node> >q;
//注意:这里使用了greater的话,那node结构体里必须重载了>比较符!
//如果没有使用greater,那就是小根堆,那node里必须重载<比较符!
node temp;
temp.name = "s3";
temp.a = 92.78;
q.push(temp);
temp.name = "s2";
temp.a = 91.66;
q.push(temp);
temp.name = "s1";
temp.a = 91.78;
q.push(temp);
temp.name = "s4";
temp.a = 91.41;
q.push(temp);
while(!q.empty())
{
node temp1 = q.top();
q.pop();
cout << temp1.name << " = " << temp1.a << endl;
}
return 0;
}