Answers for "use sort with vector c++"

C++
2

how to sort vector of struct in c++

struct point{
    int weight, position, id;
};
// . . . . . .
// your code
// for sorting using weight 
sort(points.begin(), points.end(), [] (point a, point b){
return a.weight < b.weight;
});


// for sorting using positions
sort(points.begin(), points.end(), [] (point a, point b){
return a.position < b.position;
});
Posted by: Guest on March-09-2022
1

sort vector c++

sort(begin(v), end(v), [] (int a, int b) { return a > b; }); // decrease
Posted by: Guest on April-09-2021

Browse Popular Code Answers by Language