sort()函数:sort(begin, end, cmp),其中begin为指向待sort()的数组的第一个元素的指针,end为指向待sort()的数组的最后一个元素的下一个位置的指针,cmp参数为排序准则,如果没有的话,默认以非降序排序。
实例:
#include#include #include using namespace std; bool cmp(int x,int y) { return x >y; } //sort默认为非降序排序 int main() { vector a{2,5,1,4,6}; //正向排序 sort(a.begin(),a.end()); for(auto i:a) { cout< 结果:
-VirtualBox:~/demo/stl/vector$ ./vector 1 2 4 5 6 6 5 4 2 1 6 5 4 2 1



