mercredi 1 juillet 2015

c++ custom sorting a vector

Not going to go too deep into what I am doing because it is homework and I don't need it done for me but, I do need some help. I need to be able to specify what part of a vector<vector<string>> gets sorted first and under what parameters.

Currently what I am doing works perfectly by calling

sort ( v.begin(), v.end() );

If you write out my vectors they will look something like:

5 2 4 6 12 2 5

22 51 2 5 72 1

And I might need to sort it in descending order by the 2nd column and if the 2nd column is the same I would then sort by the next specified column.

called like ./sort 2,4

would sort by second column and then 4th.

I looked around and apart from writing my own sorting algorithm for this I don't know how I would customize the sort.

Aucun commentaire:

Enregistrer un commentaire