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;
}
注意排序的区间是[起始地址,终止地址),左闭右开
代码
#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;
}
相关文章推荐
- OSI七层模型与 TCP/IP五层模型 TCP/UDP的区别
- 计算机视觉、机器学习相关领域论文和源代码
- 今天开始学习HTML5+CSS3!
- Eclipse中使用Hibernate
- zookeeper学习之二(高级特性)
- myeclipse中servers抛NullPinterException错误
- storyboard之 prepareForSegue:sender:
- 第十六周项目二--有些数的阶乘算不了
- YT04-贪心课后练习-1001—Saving HDU-(6.14日-烟台大学ACM预备队解题报告)
- 经典面试题:链表的相交与环问题
- CentOS 7学习笔记(二)之Nginx安装
- bootstarap的提示信息和缩略图
- zookeeper学习之一(简介和安装)
- php定时自动执行 需启动第一次
- 矩阵快速幂
- 几个常用的正则表达式
- Effective C++条款22解读: 将成员变量生命为private
- C++的try_catch异常
- YT04-贪心课堂练习-1005—Wooden Sticks-(6.14日-烟台大学ACM预备队解题报告)
- ubuntu开启root用户登录