Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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