版权声明:转载请标明出处 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就是降序
sort()函数默认的排序方式为升序,如果需要降序排序,可以自定义排序函数
bool comp(int x ,int y)
{
return x > y;
}
对vector 进行排序时
sort(vec.begin(),vec.end(),comp);
这样排序出的vector就是降序