samedi 31 octobre 2020

Defining a map with custom comparator where the value datastructure also has custom comparator

I wanted to define a datastructure like:

struct node {
    int x_coordinate;
    int y_coordinate;
    // some variables
};

map<node, priority_queue<node> > M;
// or lets say 
map<node, set<node> > M

The problem I am facing is I don't know how to write it's custom comparator

Also do you think if it is possible to sort the priority_queue based on the distance from the it's key node. For example let's say if I have key node with x_coordinate=0 and y_coordinate=0, and I want to insert (8,6),(4,3),(15, 9),(0,1).

So priority_queue would be something like (0,1) (4,3) (8,6) (15,9)

Aucun commentaire:

Enregistrer un commentaire