快速排序
来源:互联网 发布:网络在线警察 编辑:程序博客网 时间:2024/06/05 09:25
#include <iostream>using namespace std;extern void print(int*a, int n, int i);extern void swap(int* a, int *b);/*==================================================//功能:根据基准值将数组划分成两部分//描述:将小于基准值的数依次从左开始放置,//将大于基准值的数依次从右开始放。////参数:int* a 数组起始地址;//int low;数组起始位置//int high数组结束位置//返回值:新的基准值的位置/*==================================================*/int patition(int* a, int low, int high){int privotKey = a[low];while(low < high){while(low < high && privotKey <= a[high]) high--;swap(&a[low],&a[high]);while(low < high && privotKey >= a[low]) low++;swap(&a[low], &a[high]);}a[low] = privotKey;return low;}/*==================================================//功能:快速排序//描述:1、选取基准值,将数组分为两部分://小于基准值的和大于等于基准值的//2、用递归的方法分别对这两部分进行排序。//参数:int* a 数组起始地址;//int n;数组总长度;//返回值:/*==================================================*/void QuickSort(int* a, int low, int high){if(low < high){print(a,10,low);int privotLoc = patition(a,low,high);QuickSort(a,low,privotLoc-1);QuickSort(a,privotLoc+1,high);}}
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 旋转数组的最小数字
- 多线程并发思考--文件加锁
- form提交的几种方法
- 1009. 说反话 (20) (模拟啊 ZJU_PAT)
- 小心!!! apt-get autoremove
- 快速排序
- linux中open()函数的mode_t 含义
- MGSwipeTableCell 滑动失效 解决办法
- hdu 5040——Instrusive
- android开发中如何结束所有的activity
- java中将jsonObject字符串转化为Map对象
- HDU 1789 D( tan)P(xin)
- 【转】jvm内存调优
- spring mvc controller间跳转(重定向,传参)+struts2 转发和重定向