快速排序
来源:互联网 发布:js跨域请求 编辑:程序博客网 时间:2024/06/07 06:43
快速排序中在确定那个分割的中间量的时候需要注意几个循环的使用。
public static int partition(int []num,int low,int high){
int index=num[low];
while(low<high){
while(low<high&&num[high]>index)
{high--;}//此处右边大括号不可以放置在下面位置1处
if(low<high)
num[low]=num[high];//1
while(low<high&&index>num[low])
{low++;}//此处右边大括号不可以放置在下面位置2处
if(low<high)
num[high]=num[low];//2
}
num[low]=index;//重新赋值给num[0];
return low;//返回分割点
}
public static void quicksort(int num[],int low,int high)
{
if(low<high)
int mid=partition(num,low,high);
quicksort(num,low,mid-1);
quicksort(num,mid+1,high);
}
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- POJ 1185 状压DP
- 第十二天:poj1014(又见dfs,这次有图有真相)
- 黑马程序员-学习笔记之 多态
- 【USACO】Sorting a Three-Valued Sequence(思路)
- iOS后台持续定位并定时上传
- 快速排序
- 数列排序
- 如何在OpenCV2.3中实现CvvImage
- 【HTML/XML 1】HTML 速成总结
- 【笔记】Haskell
- GridView的使用
- 初级的I/O使用.
- Python的Descriptor在Django中的使用
- js实现选项卡功能