Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
});
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #sort #vector #struct
ADD COMMENT
Topic
Name
6+5 =