快速排序法
来源:互联网 发布:历史惊人的相似知乎 编辑:程序博客网 时间:2024/05/01 20:32
下面这张图从百度百科中转过来,一图胜百文。
下面部分自我理解编程方面的总结图。仅供参考
快速排序编程的中心思想 recursion初始条件 低位 l=0 h=n 0 ... k N a[n] |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| tmp<---| a[h] >= tmp; h--; |<--------------------------| a[h] < tmp a[l] <= tmp; l++; |---------------------->| a[l] > tmp; ....... tmp------------------>| recursion(a, 0, k-1); recursion(a, k+1, n);
下面为函数实现
#include <stdio.h>int partitions(int a[],int low,int high){ int pivotkey=a[low]; while(low<high) { while(low<high && a[high]>=pivotkey) --high; a[low]=a[high]; while(low<high && a[low]<=pivotkey) ++low; a[high]=a[low]; } a[low]=pivotkey; return low;}void qsort(int a[],int low,int high){ int pivottag; if(low<high) { //递归调用 pivottag=partitions(a,low,high); qsort(a,low,pivottag-1); qsort(a,pivottag+1,high); }}void quicksort(int a[],int n){ qsort(a,0,n);}main(){ int i,a[11]={0,11,12,5,6,13,8,9,14,7,10}; for(i=0;i<11;printf("%3d",a[i]),++i); printf("\n"); quicksort(a, 10); for(i=0;i<11;printf("%3d",a[i]),++i); printf("\n");}
- 排序--快速排序法
- 【排序】快速排序法
- 快速排序法排序
- 排序算法--快速排序法
- 排序算法--快速排序法
- 快速排序法
- 快速排序法
- 快速排序法
- 快速排序法
- 快速排序法qsort
- java快速排序法
- 通用快速排序法
- 快速排序法
- 快速排序法程序
- 快速排序法
- 快速排序法
- 快速排序法
- 快速排序法
- Javascript笔记:(实践篇)从jQuery插件技巧说起-深切解析extend办法(中篇)
- c++头文件用法
- C#中DataGridView编辑状态控制
- ant教程详解--javac,java,jar,war,delete,copy,mkdir...
- Android Listview异步动态加载网络图片
- 快速排序法
- 关于Html嵌入Applet的问题
- gsoap个人总结
- linux用户管理
- android 使用JavaMail
- 转:win7sql server2005安装
- struts,Hiernate,sping三个框架的理解
- java 5.0 内部线程池
- JS 返回上一步(退回上一步上一个网页)