快速排序和快速选择
2013-07-24 11:59
330 查看
记录,已做参考。
1.快速排序:
1.快速排序:
void quickSort(int a[],int first,int end){ int temp = a[end]; int c = first,b = end; if(first<end){ while(first<end){ while(first<end&&a[first]<temp) first++; if(first<end){ a[end] = a[first]; end--; } while(first<end&&a[end]>temp) end--; if(first<end){ a[first] = a[end]; first++; } } a[first] = temp; quickSort(a,c,first-1); quickSort(a,first+1,end); } }2.快速选择:选取一个数值中最小的K个值。
void quickSelect(int a[],int first,int end, int number){ int temp = a[end]; int c = first, b = end; if(!a&&number<=0) return ; if(c<b){ while(c<b){ while(c<b&&a[c]<temp) c++; if(c<b){ a[b] = a[c]; b--; } while(c<b&&a[b]>temp) b--; if(c<b){ a[c] = a[b]; c++; } } a[c] = temp; if((c-first)>number){ quickSelect(a,first,c-1,number); }else if((c-first)<number){ quickSelect(a,c+1,end,(number-c-1)); } } }
相关文章推荐
- ReviewForJob——快速排序(基于插入排序)+快速选择(快速排序变体)
- 快速排序及快速选择终极版
- 【数据结构笔记】快速排序(quick_sort)和快速选择(quick_select)--Python2.7
- 基于快速排序的快速选择
- 快速排序及快速选择问题
- 基于快速排序的快速选择
- 快速排序算法及其变体快速选择算法详解
- 数据结构C语言版之查找(折半选择快速等)
- java 合并排序算法、冒泡排序算法、选择排序算法、插入排序算法、快速排
- 十四、第三章再续:快速选择SELECT算法的深入分析与实现
- 快速选择合适的SIMATIC定时器
- miss go商城携“星挑客”来袭,变革快速购物新选择
- 为什么冒泡排序最好情况下(有序)时间复杂度是O(n),而快速选择是O(O^2)?
- 快速选择嵌入式系统平台,嵌入式解决方案
- java基本排序算法-插入排序-快速排序-选择排序-冒泡排序
- 快速选择图片 并且上传
- 几种常用的排序算法(快速排序,希尔排序,堆排序,选择排序,冒泡排序)
- 排序方法整理Java - 冒泡排序、选择排序、插入排序、快速排序
- 七大排序实测(计数、快速、归并、大堆、希尔、插入、选择)
- [置顶] 快速排序、冒泡排序、插入排序、选择排序