I have
vector<vector<int>> vec
in my c++ app.
Every vector of integers as an element of “big” vector has 4 INT values.
I want to sort vec basing on third value of it’s content vectors of ints (I mean every “inside” vector third element) – is it possible?
EDIT
Let’s say I’ve got a function
COST(vector<int>)
which calculates me some value based on my vector values – can I use it in comparation parameter too? It’d help me a lot more.
Sure it is.
std::sortcan take a third parameter which is the comparison function to use when sorting. For example, you could use a lambda function:Alternatively, you can pass anything else callable with signature
bool(const std::vector<int>&, const std::vector<int>&), such as a functor or function pointer.Response to edit: Simply apply your
COSTfunction toaandb: