Check out example codes for "sort vector struct c++". It will help you in understanding the concepts better.

Code Example 1

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);

Code Example 2

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);

Learn ReactJs, React Native from akashmittal.com