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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -