快速排序
2016-04-28 16:16
218 查看
#include "stdafx.h" void PrintFunc(int a[], int n) { for (int i = 0; i < n;i++) { printf("%d ", a[i]); } printf("\n"); } //快速排序 int QSort(int a[], int n) { int low = 0; int high = n - 1; int tmp, j; while (low < high) { for (j = low; j < high;++j) { if (a[j+1]<a[j]) { tmp = a[j]; a[j] = a[j +1]; a[j + 1] = tmp; } } high--; for (j = high;j>low; --j) { if (a[j]<a[j-1]) { tmp = a[j]; a[j] = a[j - 1]; a[j - 1] = tmp; } } ++low; PrintFunc(a, n); } return 0; } int _tmain(int argc, _TCHAR* argv[]) { int a[] = {9,8,7,6,5,4,3,2,1, 0}; //InsertSort(a, 10); QSort(a, 10); //PrintFunc(a, 10); return 0; }
Out:
E:\Debug>AlgoTest.exe
0 8 7 6 5 4 3 2 1 9
0 1 7 6 5 4 3 2 8 9
0 1 2 6 5 4 3 7 8 9
0 1 2 3 5 4 6 7 8 9
0 1 2 3 4 5 6 7 8 9
相关文章推荐
- 插入排序
- 树莓派B+上手小记--使用HDMI线连接显示器
- boost compile
- C++ 牛人博客(不断更新中...)
- c++ 实现百度自动搜索
- 新写的c++日志库:log4K
- VC编译错误:一个或多个多重定义的符号
- CThreadPool
- 10 Code Coverage Tools for C &amp; C++
- gcov源码,供学习使用。
- c++ string 转GUID及反转
- Java 将内容写入到某个文件中
- select、poll、epoll之间的区别总结
- Jenkins 简介和安装
- Java读取txt或其他文件以UTF-8格式输出的时候,第一行代码出现“?”乱码的原因及解决方案!
- Android 去除最上面应用名称及图标
- digest 用户认证 response生成算法
- 以短链服务为例,探讨免AppKey、免认证、Ajax跨域调用新浪微博API
- 字符串反转
- Logback常用配置详解