mardi 24 janvier 2017

Selectively sort vector c++

I have the following vector:

vector<unsigned> vec = {5, 6, 5, 4, 1, 3, 0, 4}

Now I want to sort this vector lexicographically by odd indices (and if odd indices are equal, then by the even indices). Such that the sorted vector "vec" is:

   {0, 4, 1, 3, 5, 4, 5, 6}

I know std::sort is going to sort "vec" entirely. Is it possible to use std::sort to sort the vector selectively. Similarly for std::lower_bound. Is it possible to find the lower_bound using odd indices only.

Aucun commentaire:

Enregistrer un commentaire