sort()函数

头文件<algorithm>

对结构体排序

struct node
{
    string name;
    string phone;
    int birth;
}  a[15];

bool cmp(node x,node y)
{
    return x.birth<y.birth ;
        //从大到小
}

......

for(int i=0;i<N;i++)
cin>>a[i].name>>a[i].birth>>a[i].phone;

sort(a,a+N,cmp);

 

posted on 2021-03-27 16:25  白夜just  阅读(69)  评论(0编辑  收藏  举报

导航