mardi 30 juin 2015

I need to sort a vector<vector<int> > vecOfVectors; lexicographically.

So, my vecOfVectors before sorting lexicographically is:

((0,100,17,2),(2,3,1,3),(9,92,81,8),(0,92,92,91),(10,83,7,2),(1,2,3,3))

In order to do so I am using the following function:

std::sort(vecOfVectors.begin(),vecOfVectors.end(),lexicographical_compare);

So, my vecOfVectors after sorting lexicographically is now:

((0,92,92,91),(0,100,17,2),(1,2,3,3),(2,3,1,3),(9,92,81,8),(10,83,7,2))

Now given a vector I need to search its position in this sorted vecOfVectors -- somthing like binary search will work great. Is there some build in function in c++ stl that I can use to perform the binary search?

For example: the position of (0,92,92,91) is 0; position of (0,100,17,2) is 1; position of (1,2,3,3) is 2; position of (2,3,1,3) is 3; position of (9,92,81,8) is 4; position of (10,83,7,2) is 5.

Aucun commentaire:

Enregistrer un commentaire