C++标准库函数sort

#include <iostream>
#include <algorithm>
using namespace std;
bool compare(int a, int b)
{
    return a>b; //降序排列
    // return a<b;  //默认的升序
}
int main()
{
    int A[6] = {3,1,5,7,4,2};
    sort(A, A+6, compare);
    //sort(A, A+6, greater<int>()); //使用标准库函数greater<Type>
    for (int i=0; i<6; i++)
    {
        cout << A[i] << " ";
    }
    cout << endl;
    return 0;
}

  

posted @ 2020-08-27 19:55  大战拖延  阅读(144)  评论(0)    收藏  举报