c++ - How to order a set< pair< pair<int, int>, double > > for the second value "double"? -
i super new in c++ , struggling this: want organize second component of set:
set< pair <pair<int, int>, double > > map int n_t = 10, n_r = 10; (unsigned int i_t = 0; i_t < n_t; i_t++ ) { for(unsigned int i_r = 0; i_r < n_r; i_r++ ) { double_t dr = i_t*i_r ; map.insert( make_pair(make_pair(i_r, i_t) ,dr)); } }
and want organice second component. have try , dont know how to it:
sort(map.begin(), map.end(), [](const pair<pair<int,int> &x, double>,const pair<pair<int,int>, double> &y) { return x.second < y.second; });
thanks!!
if wish sort according .second
element of pair, why not placing double
in front of pair<int,int>
? sorting orders pairs first element second element, instead of
set< pair <pair<int, int>, double > > map
you use
set< pair <double, pair<int, int> > > map
also suggest not using keywords variable names (map
in-built data structure in c++)
Comments
Post a Comment