Dijkstra algoriithim

sir how can I the sorting in the set of pair to be according the second parameter?
I have used a custom class like:
set<pair<T,int>, compare>s; —>(the compiler gives me error message)
so what is the solution?

hello @mzk1994

u need to make functor for custom comparision and then pass its name in the second argument of the set.
example->

struct CustomCompare   //declaring functor, u can use class also  
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }

    bool operator()(const Person& lhs, const Person& rhs)
    {
        return lhs.getAge() < rhs.getAge();
    }
};

// and then u can pass it in ur set as->
 set<Person,CustomCompare> setOfPersons;

    setOfPersons.insert(Person("Person 1", 25));
    setOfPersons.insert(Person("Person 2", 16));
    setOfPersons.insert(Person("Person 3", 28));
    setOfPersons.insert(Person("Person 4", 9));

    for(set<Person,CustomCompare>::iterator it = setOfPersons.begin(); it!=setOfPersons.end(); ++it)
    {
        cout << it->getName() << " , age : " << it->getAge()<< endl;
    }





template
class compare{
public:
bool operator()(const pair<T,int>&p1,const pair<T,int>&p2)const{
return p2.second>p1.second;
}
};
template
void graph::dijkstra(T src){
unordered_map<T,int>dist;
for(auto node:hashmap)
dist[node.first]=INT_MAX;
dist[src]=0;
set<pair<T,int>,compare>s;
}

what is the problem !!!
why the compiler gives me error about set
I want to make the comparison based on second parameter

@mzk1994

pls save the complete code in cb ide , and then share its link with me

how could reach cb ide?

go to this link -> https://ide.codingblocks.com/
paste complete code in the editor
and then press ctrl +s and then save

a url will be generated , share that url with me

I saved it, then how can I share it with you?

when u click on save button , a url will be generated in ur search bar , share that url with me (in reply).

do you recieved any thing?

no ,
u will get url something like this-> https://ide.codingblocks.com/s/461099
in ur search bar.
copy that url and paste here

Coding Blocks IDE

u have made a genereic functor.
so while passing it in set , u need to mention the datatype as well.

for example->

set<pair<T,int>,Compare<int> > s;

or  for any other dataype use its name
set<pair<T,int>,Compare< DatatypeNaME > > s;

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.