C++比较器_重载运算符

#include <iostream>
#include <algorithm>
using namespace std;

struct student{
    int ID;
    int Age;
    int Score;
};
student stu [3] = {
    {1, 18, 88},
    {2, 19, 90},
    {3, 20, 70}
};
bool operator < (const student &a, const student &b)
{
    return (a.Score < b.Score);
}

int main()
{
    sort(stu, stu + 3);
    for(int i = 0; i < 3; i++)
        cout << stu[i].ID << ' ' << stu[i].Age << ' ' << stu[i].Score << endl;
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Cris_7/article/details/82928903
今日推荐