sort()函数排序vector

版权声明:转载请标明出处 https://blog.csdn.net/martinkeith/article/details/89844556

sort()函数默认的排序方式为升序,如果需要降序排序,可以自定义排序函数

bool comp(int x ,int y)
{
    return x > y;
}

对vector 进行排序时

sort(vec.begin(),vec.end(),comp);

这样排序出的vector就是降序

猜你喜欢

转载自blog.csdn.net/martinkeith/article/details/89844556