c++ sort用法 学习笔记

c++ sort排序函数,需要加库#include<algorithm>,语法描述:sort(begin,end,cmp),cmp参数可以没有,如果没有默认非降序排序。

首先是升序排序:

#include<iostream>
#include<algorithm>//函数库
#include<cstring>
using namespace std;
int main()
{
    int a[6]={6,5,4,3,2,1};
    for(int i=0;i<6;i++)
    {
        sort(a,a+6);//调用c++sort函数
        cout<<a[i]<<' ';
    }
    return 0;
}

sort(名称,名称+排序数量)

如果大家满意就关注我吧!
原文地址:https://www.cnblogs.com/yihengblog/p/10199281.html