jeudi 11 novembre 2021

How to sort the vector of pair? [duplicate]

Considering vector<pair<string,double>>
let inputs be:

hey 1.2
hello 2.9
help 1.2
hay 1.2
horse 2.5
hot 0.8

sort(vec.begin(), vec.end() , comp);

How to write a comparator so that it sort the vector:

1)sorting ascending according to 2nd value
2)If equal sort it using occurence of the 1st value

Eg: hey ,hay, help have same 2nd value...So it should be sorted in the order provided by user...
So it should be hey,help,hay

Aucun commentaire:

Enregistrer un commentaire