约 10 分钟
结构体也能用 sort 排,但要告诉它按哪一项比。给学生按年龄从小到大排:bool cmp(Student a,Student b){return a.age<b.age;},再 sort(s, s+n, cmp);。
sort
bool cmp(Student a,Student b){return a.age<b.age;}
sort(s, s+n, cmp);
想按年龄从小到大,比较函数里写 a.age<b.age 还是 >?
a.age<b.age
>
登录 后可看答案