快速排序
来源:互联网 发布:模拟经营类游戏 知乎 编辑:程序博客网 时间:2024/06/16 07:35
实现思路一:
int Partition(int data[], int length, int start, int end){if (data==NULL || length<1 || start<0 || end>=length)throw new exception("Invalid Parameters!");int index = start + rand()%(end-start+1);Myswap(data[index], data[end]);int small = start - 1;for (index=start; index<end; ++index ){if (data[index] < data[end]) //找比基值小的{++small;if (small != index)Myswap(data[index],data[small]);}}++small; //分界处Myswap(data[small], data[end]);return small;}void QuickSort(int data[], int length, int start, int end){if (start==end)return;int index = Partition(data,length,start,end);if (index>start)QuickSort(data,length,start,index-1);if (index<end)QuickSort(data,length,index+1,end);}
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- JAVA 【finding runway length】
- 1027. 打印沙漏(20)
- 字符串逆置算法
- [Android Studio 权威教程]多渠道打包和一键完成(全部产品)打包并签名
- ArcGIS Server 10.1找回登录用户名和重置密码
- 快速排序
- C# 窗口实现定时关机系统
- 1028. 人口普查(20)
- 怎么进入 BAT 的研发部门?
- Square Coins 1398 (母函数)
- C++之容器---vector
- 事件(C# 编程指南)
- Ubuntu12.04启动后无法进入图形界面的解决方法
- poj 1426 Find The Multiple 简单搜索