整数排序 II
来源:互联网 发布:嘟嘟牛破译软件 编辑:程序博客网 时间:2024/06/06 11:00
给一组整数,按照升序排序。使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法。
解题代码: void sortIntegers2(vector<int>& A) {
// Write your code here
QuickSort(A,0,A.size()-1);
}
void QuickSort(vector<int>& A,int first,int end)
{
if(first<end) {
int pivot=Partition(A,first,end);
QuickSort(A,first,pivot-1);
QuickSort(A,pivot+1,end);
}
}
int Partition(vector<int>& A,int first,int end)
{
int i=first;
int j=end;
while(i<j)
{
while(i<j&&A[i]<=A[j]) j--;
if(i<j){
swap(A[i],A[j]);
i++;
}
while(i<j&&A[i]<=A[j]) i++;
if(i<j){
swap(A[i],A[j]);
j--;
}
}
return i;
}
};
解题思路;换为其他算法,参考课本即可。
- 【LintCode】整数排序II
- 整数排序II-lintcode
- lintcode_整数排序 II
- LintCode-整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- 464.整数排序 II
- 整数排序 II
- 整数排序 II
- 整数排序II
- 整数排序 II
- 整数排序 II
- 整数排序 II
- LintCode 整数排序 II
- 整数排序II
- opencv中的图形存储空间
- 移动端拖拽
- Java中的String和String pool
- **洛谷P1028 数的计算(NOIp2001)
- java 虚拟机 类加载
- 整数排序 II
- 1.整洁代码
- [LeetCode]Evaluate Reverse Polish Notation
- vb.net 教程 11-1 打印组件 4 PrintDocument 3
- 技术| Android ConstraintLayout初级使用记录
- 创建模式之一 ---工厂模式
- Docker容器的重启策略及docker run的--restart选项详解
- android 页面下拉刷新,添加新数据
- HTML5中Audio标签ended属性的使用