I have these structures:
typedef std::pair<unsigned int, std::pair<int, int> > myPair;
typedef std::set< myPair> Graph;
Graph g;
What is the right comparison function for sorting the graph like?
std::sort(g.begin(), g.end(), Cmp());
I tried doing something like this:
struct Cmp{
bool operator()(const myPair& l, const myPair& r)const{
return l.second.second < r.second.second;
}
};
I want the set to be ordered according to the second element of the most inner pair. Is it possible?
a = (std::make_pair(0,std::make_pair(1,1)));
b = (std::make_pair(0,std::make_pair(1,2)));
c = (std::make_pair(0,std::make_pair(1,0)));
d = (std::make_pair(1,std::make_pair(2,0)));
The result would be:
Before the ordering
c = (0,(1,0)), a = (0,(1,1)), b = (0,(1,2)), d = (1,(2,0)
After the ordering
c = (0,(1,0)), d = (1,(2,0), a = (0,(1,1)), b = (0,(1,2))
Question: Is it possible to create the set in this ordering manner?