您的位置:首页 > 其它

sort例子

2015-06-21 16:10 423 查看
sort(起始地址,终止地址,排序函数)

注意排序的区间是[起始地址,终止地址),左闭右开

代码

#include <iostream>

#include <string>

#include <math.h>

#include <algorithm>

#include <vector>

using namespace std;

bool cmp(int a,int b);

int main()

{

    int x[10] = {1,3,2,5,4,7,6,8,0,9};

    sort(x,x+10,cmp);

    for(int i=0;i<10;i++)

        cout << x[i] << ' ';

    return 0;

}

bool cmp(int a,int b)

{

    return a>b;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: