464. 整数排序 II
来源:互联网 发布:owncloud windows安装 编辑:程序博客网 时间:2024/06/05 07:00
给一组整数,按照升序排序。使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法。
样例
给出 [3, 2, 1, 4, 5]
, 排序后的结果为 [1, 2, 3, 4, 5]
。
public class Solution {
/** @param A: an integer array
* @return:
*/
public void sortIntegers2(int[] A) {
// write your code here
Wsort(A, 0, A.length-1);
}
public int partiton(int[] A, int low, int high)
{
int first = low;
int last = high;
int key = A[low];
while(first < last)
{
while(first < last && A[last] >= key)
{
last--;
}
if(first < last) A[first] = A[last];
while(first < last && A[first] <= key)
{
first++;
}
if(first < last) A[last] = A[first];
}
A[first] = key;
return first;
}
public void Wsort(int[] A, int low, int high)
{
if (low < high)
{
int index = partiton(A, low, high);
Wsort(A, low, index-1);
Wsort(A, index+1, high);
}
}
}
阅读全文
0 0
- 464.整数排序 II
- 464. 整数排序 II
- 【LintCode】整数排序II
- 整数排序II-lintcode
- lintcode_整数排序 II
- LintCode-整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- LintCode 整数排序 II
- 42. Trapping Rain Water
- loj6009「网络流 24 题」软件补丁(状态压缩+spfa)
- 抽象A
- 不定宽高的水平垂直居中
- eclipse中项目发布到tomcat中之后的目录结构
- 464. 整数排序 II
- Linux(Ubuntu)安装和完美卸载Apache详细教程和配置多域名、端口映射
- 隐私政策
- Java系列书籍推荐下载
- java获取properties配置文件最简单方法
- 最小生成树Kruskal算法朴素版 C语言实现
- Python学习Day1
- Git 初次学习笔记
- 图论入门测试之后。