我有一个指向a的优先级队列struct city.我修改优先级队列外的这些指针指向的对象,并希望告诉优先级队列根据新值"重新排序"自己.
我该怎么办?
例:
#include <iostream>
#include <queue>
using namespace std;
struct city {
int data;
city *previous;
};
struct Compare {
bool operator() ( city *lhs, city *rhs )
{
return ( ( lhs -> data ) >= ( rhs -> data ) );
}
};
typedef priority_queue< city *, vector< city * >, Compare > pqueue;
int main()
{
pqueue cities;
city *city1 = new city;
city1 -> data = 5;
city1 -> previous = NULL; …Run Code Online (Sandbox Code Playgroud)