递归-快速排序
来源:互联网 发布:网络金融部怎么样 编辑:程序博客网 时间:2024/06/07 02:39
本文参考:
坐在马桶上看算法:http://developer.51cto.com/art/201403/430986.htm
实现代码:
#include<iostream>using namespace std;void quickSort(int a[], int l,int r) {int i, j, k, temp;if (l > r)return;temp = a[l];//存放基准数i = l;j = r;while(i != j) {//顺序很重要,一定要从右边开始,找比基准数小的//因为基准数在左边,必须先让右边停止,才可以做最后的和基准数交换while (a[j] >= temp && i < j)j--;//找左边比基准数大的while (a[i] <= temp && i < j)i++;//交换左右边找到的数if (i < j) {k = a[i];a[i] = a[j];a[j] = k;}}//最终基准数归位a[l] = a[i];a[i] = temp;quickSort(a, l, i - 1);quickSort(a, i + 1, r);}void main() {int n, a[100];cin >> n;for (int i = 0; i < n; i++)cin >> a[i];quickSort(a, 0, n - 1);for (int i = 0; i < n; i++)cout<<a[i]<<" ";}
阅读全文
0 0
- 快速排序递归调用
- 快速排序,递归算法
- 快速排序递归算法
- 递归实现快速排序
- 快速排序(递归)
- 快速排序(递归)
- 快速排序----非递归
- 快速排序+递归实现
- 快速排序【递归版】
- 递归快速排序
- 递归快速排序
- 快速排序算法(递归)
- 递归版快速排序
- 快速排序 非递归
- 快速排序(递归)
- 快速排序 递归
- 递归实现快速排序
- 递归--快速排序
- flume1.7 TailDirSource断点续传与文件更名后数据重复采集的bug修复
- Gradle升级4.1后style文件中window切换animation报错
- maven pom
- hadoop 之 如何从Sqoop官网下载适用于集群的版本
- 有意思的递归
- 递归-快速排序
- 机器学习中各种基本的回归模型的汇总
- php 使用phpqrcode生成二维码并上传到OSS
- 数据库发展史
- eclipse上从mybatis java代码跳转至xml的插件
- 添加购物&查看购物车
- oracle使用exp与imp对数据迁移备份的方法
- jvm 内存基本概念
- 备注linux一些指令