Evanyou Blog 彩带
扩大
缩小

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(名称,名称+排序数量)

 

posted @ 2018-12-30 14:09  yi_heng  阅读(267)  评论(0编辑  收藏  举报