C++コンパレータの実装_関数#カンスウ#

5029 ワード

#include 
#include 
using namespace std;

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

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