快速排序实例
来源:互联网 发布:日本人的饮食知乎 编辑:程序博客网 时间:2024/05/07 00:38
# include <stdio.h>
int FindPos(int * a, int low, int high);
void QuickSort(int * a, int low, int high);
int main(void)
{
int a[6] = {-2, 1, 0, -985, 4, -93};
int i;
QuickSort(a, 0, 5); //第二个参数表示第一个元素的下标 第三个参数表示最后一个元素的下标
for (i=0; i<6; ++i)
printf("%d ", a[i]);
printf("/n");
return 0;
}
void QuickSort(int * a, int low, int high)
{
int pos;
if (low < high)
{
pos = FindPos(a, low, high);
QuickSort(a, low, pos-1);
QuickSort(a, pos+1, high);
}
}
int FindPos(int * a, int low, int high)
{
int val = a[low];
while (low < high)
{
while (low<high && a[high]>=val)
--high;
a[low] = a[high];
while (low<high && a[low]<=val)
++low;
a[high] = a[low];
}//终止while循环之后low和high一定是相等的
a[low] = val;
return high; //high可以改为low, 但不能改为val 也不能改为a[low] 也不能改为a[high]
}
- 快速排序实例
- c++快速排序实例
- 快速排序实例
- 快速排序-php实例
- 快速排序实例
- 快速排序实例
- 快速排序的实例
- 快速排序qsort算法实例
- C实例---快速排序(冒泡排序)
- 快速排序原理解析及实例应用
- 快速排序算法及C++实例
- Java实例17 - 快速排序 quick sort
- 快速排序qsort()源码及使用实例。
- 快速排序实例化(详细过程)
- 数据结构14-排序方法之快速排序的实例
- 最好理解的快速排序 :实例解析输入数组,排序
- 排序与查找实例(三):快速排序
- php冒泡排序与快速排序实例详解
- centos 用户和组,权限,添加删除详解
- VS_2003 打开文件项目历史记录删除
- We have received 3 comments in first 3 days (http://itunes.apple.com/app/wikinodes/id433834594?mt=8)
- vs2010中臃肿的ipch和sdf文件
- [005] Android开发中常用的Eclipse快捷键
- 快速排序实例
- uafxcwd.lib(afxmem.obj) : error LNK2005
- 【转】如何对PHP程序中的常见漏洞进行攻击(上)
- linq语句转SQL语句
- 云端记事本
- StringTokenizer类的用法
- php学习中
- 原来用U盘安装LINUX操作系统是这么的简单
- HDU3333(线段树/数状数组 + hash)