快速排序QuickSort
2015-04-11 09:51
225 查看
void Qsort(int * numbers,int low,int high) { if(low<high) { int i=low+1,j=high; int ran; ran = (low + high) / 2; swap(&numbers[ran], &numbers[low]); int key = numbers[low]; while(i<=j){ while((numbers[j]>key)&&(low<=j)) j--; while((numbers[i]<=key)&&(i<=high))//note: either i, or j >= or <=,or will cause infinite loop when numbers have //same number. i++; if (i < j) { swap(&numbers[i],&numbers[j]); swap(&orders[i], &orders[j]); } } swap(&numbers[low], &numbers[j]);//swap j!! Qsort(numbers,orders,low,j-1); Qsort(numbers,orders,j+1,high); } }
快速排序中比较快的版本//kind of faster version
相关文章推荐
- 算法导论 - QuickSort 快速排序 C++实现
- 快速排序 quicksort
- 快速排序-Quicksort
- 快速排序(QuickSort)
- 快速排序 优化 (QuickSort)Java数据结构与算法
- 快速排序测试(QuickSort)
- 【快速排序】QuickSort(三种实现方法)c++描述
- 快速排序 QuickSort Java代码
- 快速排序——QuickSort
- 快速排序(QuickSort)
- C++ 快速排序QuickSort的实现
- 快速排序:Sort:QuickSort using C++
- 快速排序 quicksort 细节问题
- Java 快速排序 quicksort
- 这个代码怎么改??Help快速排序 quicksort
- 快速排序quicksort的实现与分析
- DualPivotQuickSort 双轴快速排序 源码
- 第七章快速排序之“快速排序的随机化版本RANDOM-QUICKSORT”
- 快速排序 QuickSort
- 算法第四版学习笔记之快速排序 QuickSort