C++ sort()与for_each()

#include <bits/stdc++.h>
using namespace std;

bool compare(int a,int b)
{
    return a>b; //a>b从大到小 
                //a<b从小到大 
}

void print(int e)
{
    cout<<e<<" ";
}

int main()
{
    int a[10]={5,9,2,7,1,10,3,6,4,8};
    sort(a,a+10,compare);
    //sort(a,a+10);//从小到大 
    for_each(a,a+10,print);
    return 0;
} 
/**************************************
 *            小柳学渣
 *        2019/1/24  10:59
 *************************************/

猜你喜欢

转载自blog.csdn.net/l503301397/article/details/86653712