c++ - Sort Array but keep row indexes -
i have array this:
names, state, houseprice, carsprice
john, wi, 200, 100 jimmy, mi, 100, 90 ...
how sort houseprice , car price without changing elements in same row? sort whole row of "john" based on houseprice , carprice against row in array keep in row together.
this have far,
for (int i=0;getline(file,(names[i]),',');i++) { getline(file, states[i], ','); getline(file, houseprice[i], ',') ; getline(file, carprice[i]); }
how want sort houseprice , carprice against row without losing name , states along row.
just project field interested in part of comparison function object otherwise treat objects 1 unit:
house array[] = { ... }; // sort houseprice; similar other attributes: std::sort(std::begin(array), std::end(array), [](house const& h0, house const& h1) { return h0.houseprice < h1.houseprice; });
Comments
Post a Comment