#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct Rule1 {
bool operator()(const int& a1, const int& a2)const {
return a1 % 10 < a2 % 10;
}
};
struct Student {
char name[10];
double GPA;
int age;
};
struct StudentRule1 {//排序规则
bool operator()(const Student& a1, const Student& a2)const {
return a1.GPA < a2.GPA;
}
};
int main()
{
Student Students[3] = { {"Jack",3.5,20},{"al",3.0,9},{"zty",2.0,15}
};
sort(Students, Students + sizeof(Students) / sizeof(Students), StudentRule1());
for (int i = 0; i < 3; i++)
{
printf("%f", Students[i].GPA);
}
}
太强大了,可以很方便地对数组里的元素进行排序