I was looking a way to sort struct using sort() function of STL:Algorithm library. I found a couple of codes using vector to do this. for example
struct person {
std::string name;
int age;
};
bool sort_by_name( const person & lhs, const person & rhs )
{
return lhs.name < rhs.name;
}
bool sort_by_age( const person & lhs, const person & rhs )
{
return lhs.age < rhs.age;
}
int main() {
std::vector<person> people;
// fill in the vector
std::sort( people.begin(), people.end(), sort_by_name );
std::sort( people.begin(), people.end(), sort_by_age );
}
我想知道,如果不使用矢量的话,是否有可能进行分类?如果是的话,如何进行?