Answers for "sort vector struct c++"

C++
3

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);
Posted by: Guest on August-01-2020
0

sorting vector of structs 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);
Posted by: Guest on July-27-2020

Browse Popular Code Answers by Language