Horje
how to sort vector of struct in c++ Code Example
sort vector c++
//me
vector<int> v{2,5,3,4,0,1};
sort( v.begin(), v.end() );

//v is now {0,1,2,3,4,5}
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;
});
sort vector struct c++
struct data{
    string word;
    int number;
};


bool my_cmp(const data& a, const data& b)
{
    // smallest comes first
    return a.number < b.number;
}

std::sort(A.begin(), A.end(), my_cmp);
sort vector c++
sort(begin(v), end(v), [] (int a, int b) { return a > b; }); // decrease




Cpp

Related
sorting using comparator in c++ Code Example sorting using comparator in c++ Code Example
Get handle in C++ Code Example Get handle in C++ Code Example
c++ erase last element of set Code Example c++ erase last element of set Code Example
c++ how to make a negative float positive Code Example c++ how to make a negative float positive Code Example
platform io change baud rate Code Example platform io change baud rate Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10