c++ - Sorting a list of structs by an element -
i have got struct below:
struct man { string surname; string name; char sex; int birth_year; int age; man * next; }; how can sort list alphabetically surname?
i know how bubble sort arrays, can't handle list :/
in order make std::list::sort work need overload < operator of class.
in case this
//n.b. untested code bool operator< (const man& other) { toupper(this->surname) < toupper(other->surname); } you call overload of sort wich takes comp function argument. see here.
Comments
Post a Comment