c++ struct sort code example
Example 1: sort in descending order c++ stl
sort(arr, arr + n, greater<int>())
Example 2: 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);