#include<vector>
#include<algorithm>
#define NUM 10
using namespace std;
//自定义结构体的排序
struct Student {
int id;
int age;
};
vector<Student> stus;
bool cmd(Student a, Student b) {
if (a.age < b.age)
return true;
return false;
}
void main() {
for (int i = 0; i < NUM; i++) {
Student s;
s.id = i;
s.age = rand() % 30;
stus.push_back(s);
}
sort(stus.begin(),stus.end(),cmd);
for (int i = 0; i < NUM; i++) {
printf("student NO %d,age : %d\n",i,stus[i].age);
}
system("pause");
}