如何排序姓名,年龄和得分下面的代码......所有这三个领域排序矢量
#include <string>
#include <vector>
#include <algorithm>
struct student_t
{
std::string name;
int age, score;
};
bool by_more_than_1_field(student_t const &lhs, student_t const &rhs)
{
// sort by name, age and score
}
int main()
{
std::vector<student_t> students;
// populate students
std::sort(students.begin(), students.end(), by_more_than_1_field);
}
我们的答案是相同的。很难说哪一个更容易阅读/维护... – jslap 2009-11-16 14:13:07