#include #include #include #include using namespace std ; class Person { public: string name; int age; }; bool sortPerson (const Person& p1, const Person& p2) { if (p1.age != p2.age) { return p1.age < p2.age; // Sort by age } return p1.name < p2.name; // If ages are equal, sort by name } int main() { vector people = { {"Jon", 60 }, {"Von", 60 }, {"Neumann", 60 }, {"Turing", 22 }, {"Alan", 22 } }; sort(people.begin(), people.end(), sortPerson ) ; for (const auto& person : people) { cout << person.name << " (" << person.age << ")" << endl; } cout << "----------------" << endl ; // Sort people by age in ascending order, then by name in ascending order sort(people.begin(), people.end(), [](const Person& p1, const Person& p2) { if (p1.age != p2.age) { return p1.age < p2.age; // Sort by age } return p1.name < p2.name; // If ages are equal, sort by name }); for (const auto& person : people) { cout << person.name << " (" << person.age << ")" << endl; } return 0; }