排序——快速排序
来源:互联网 发布:驾驭大数据 百度云 编辑:程序博客网 时间:2024/05/21 13:22
首先定义一个存储数据的结构,该结构定义如下:
#define N=20 //N为待排序序列的个数
typedef struct
{
int key;
DataType other;
}RecType ;
RecType R[N+1];
(1)定义N+1主要是为了R[0]不用存放数据,从1计数到N,数组的下标直接和序号直接对应;
(2)预留R[0]可做其他用处,比如:监视哨,或者记录交换的辅助空间。
一次划分和快速排序递归算法的函数实现
int partition (RecType R[],int low ,int high)
{
int k;
R[0]=R[low];
k=R[0].key;
while(low<high)
{
while((low<high)&&R[high].key>k)
high--;
if(low<high)
R[low]=R[high];
while((low<high)&&R[low].key<k)
low++;
if(low<high)
R[high]=R[low];
}
R[low]=R[0];
return low;
}
void QSort(RecType R[],int low,int high)
{
int part;
if(low<high)
{
part=partition(R,low,high);
QSort(R,low,part-1);
QSort(R,part+1,high);
}
}
0 0
- 排序—快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 排序——快速排序
- 交换排序—快速排序
- 排序算法—快速排序
- 排序算法—快速排序
- 内部排序—快速排序
- 排序方式—/冒泡排序/快速排序
- 排序3——堆排序,归并排序,快速排序
- 快速排序—java
- POX学习笔记:从POX启动开始——boot.py文件解读
- Mysql优化读书笔记
- Several points on OPNET simulator installation and system environment configurations
- 闵可夫斯基距离
- Struts2 文件上传 之 文件类型 allowedTypes
- 排序——快速排序
- SELECT语句逻辑执行顺序,你知道吗?
- 黑马程序员_C语言的一些总结
- 协同OA2014的狂奔与驻守
- Hibernate的一个开发工具(OpenSession()和getCurrentSession())
- c++ string类的一些注意
- Windows窗口相关的一些概念解释
- freeman链码
- LAMP(Linux+Apache+Mysql+PHP)环境搭建