I have
vector> vec
in my c++ app.
Every vector of integers as an element of \"big\" vector has 4 INT valu
Sure it is. std::sort
can take a third parameter which is the comparison function to use when sorting. For example, you could use a lambda function:
std::vector> vec;
// Fill it
std::sort(vec.begin(), vec.end(),
[](const std::vector& a, const std::vector& b) {
return a[2] < b[2];
});
Alternatively, you can pass anything else callable with signature bool(const std::vector
, such as a functor or function pointer.
Response to edit: Simply apply your COST
function to a
and b
:
std::sort(vec.begin(), vec.end(),
[](const std::vector& a, const std::vector& b) {
return COST(a) < COST(b);
});