lintcode_整数排序 II
来源:互联网 发布:服务器上的java 编辑:程序博客网 时间:2024/06/03 21:21
1.描述:
给一组整数,按照升序排序。使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法。
样例
2.思路:给出 [3, 2, 1, 4, 5]
, 排序后的结果为 [1, 2, 3, 4, 5]
。
先把vector里的数导入到一个数组中,然后用sort对数组排序,再把排序完的数组导入vector中。
3.代码:
int a[100000];
void sortIntegers2(vector<int>& A) {
vector<int>::iterator i;
int p;
for(i=A.begin(),p=0;i!=A.end();i++,p++)
{
a[p]=*i;
}
sort(a,a+p);
for(i=A.begin(),p=0;i!=A.end();i++,p++)
{
*i=a[p];
}
}
4.感想:感觉这个方法比较low,但是总归是过了
阅读全文
0 0
- lintcode_整数排序 II
- LintCode_两个整数相除
- 【LintCode】整数排序II
- 整数排序II-lintcode
- LintCode-整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 464.整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- LintCode 整数排序 II
- MySQL常用查询语句
- 367. Valid Perfect Square
- 明朝崇祯元年状元刘若宰后裔在松滋
- 视图外连接空字符串问题的解决
- App的启动过程(3)应用进程侧-主线程的处理
- lintcode_整数排序 II
- 让你的node、express服务器支持https
- GroupCoordinator分析
- 自定义RecycleView实现TV应用上的item焦点获取以及设置当前选中的item居中
- How to Change Hadoop Daemon log4j.properties
- 仿UC视频播放(iOS源代码)
- cstring和string区别
- Java回炉重造(二)静态代理
- K-means均值聚类算法的原理与实现