64,687
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <queue>
using namespace std;
struct Node
{
Node(int n,int d,Node *right=0):num(n),dist(d),next(right) //你给num值,与dist有关?你哪里赋值dist了?
{
}
Node()
{
dist=INT_MAX;
prev=0;
}
int num;
int dist;
int prev;
Node*next;
};
struct cmp
{
bool operator() (const Node *a,const Node *b)
{
return a->dist < b->dist;
}
};
int main()
{
priority_queue<Node*,vector<Node*>,cmp> q;
q.push(new Node(1,4));
q.push(new Node(1,2));
q.push(new Node(1,6));
while(!q.empty())
{
cout<<q.top()->dist<<" ";
q.pop();
}
return 0;
}