快速排序 一个简单示例
2013-03-10 20:17
225 查看
sort.c
void swap(int iList[], int a, int b) { int temp; temp = iList[a]; iList[a] = iList[b]; iList[b] = temp; } void quickSort(int iList[],int left, int right) { int last; int i; if(left < right) { swap(iList, left, (left + right) / 2);//left original value is 0, that is wrong!! last = left; for(i = left + 1; i <= right; i++) { if(iList[i] < iList[left]) { swap(iList, i, last);//usefull only when iList[i] >= iList[left] has happened } } swap(iList, left, last); quickSort(iList, left, last - 1); quickSort(iList, last + 1, right); } }
main.c
//a example of quick sort #include <stdio.h> int iList[] = {23, 43, 55, 122, 11, 234}; int main(void) { void quickSort(int iList[], int left, int right); int iLength; int i; iLength = sizeof(iList) / sizeof(iList[0]); quickSort(iList, 0, iLength - 1); for(i = 0; i < iLength; i++) { printf(i == iLength - 1 ? "%d\n" : "%d,", iList[i]); } return 0; }
相关文章推荐
- 直接插入排序 一个简单示例
- 一个快速排序 和 直接插入排序 的简单 c程序
- 快速排序就这么简单
- 一个主域名服务器DNS快速简单的配置方法
- Skinned Mesh 原理解析和一个最简单的实现示例 作者:n5 Email: happyfirecn##yahoo.com.cn Blog: http://blog.csdn.net/n5
- 【Eclipse RCP】1. 一个简单的RCP程序示例
- 消除原理____假设数组中有一个数字出现的次数超过了数组长度的一半,试编程找出这个数字(qosrt 快速排序 哈希)
- 下面是一个notify.sh脚本的简单示例
- mybaits入门---快速搭建一个简单的mybatis项目
- 利用Maven快速创建一个简单的spring boot 实例
- (WCF)示例一: 构建一个简单的WCF Service: MagicEightBall
- 如何快速搭建一个简单图像搜索引擎
- VC++6.0 一个简单的图片按钮示例
- SQL 数据库 学习 007 通过一个示例简单介绍什么是字段、属性、列、元组、记录、表、主键、外键
- 分形技术的一个简单示例——雪花图案(AS3实现)
- 排序都有哪几种方法?请列举。用JAVA实现一个快速排序。
- Ajax得知(两)—— 一个简单的Ajax示例
- C语言实现 排序源程序(包括直接插入、希尔、冒泡、快速、简单选择、堆排序)
- Objective-C ,ios,iphone开发基础:快速实现一个简单的图片查看器
- 一个简单的freemarker应用示例