排序算法之----快速排序算法
来源:互联网 发布:c语言打印所有梅花数 编辑:程序博客网 时间:2024/05/01 23:09
// 《剑指Offer——名企面试官精讲典型编程题》代码// 著作权所有者:何海涛#include "stdafx.h"#include <stdlib.h>#include "Array.h"#include <exception>// Random Partitionint RandomInRange(int min, int max){ int random = rand() % (max - min + 1) + min;// min ~ max return random;}void Swap(int* num1, int* num2){ int temp = *num1; *num1 = *num2; *num2 = temp;}int Partition(int data[], int length, int start, int end){ if(data == NULL || length <= 0 || start < 0 || end >= length) throw new std::exception("Invalid Parameters"); int index = RandomInRange(start, end); Swap(&data[index], &data[end]); int small = start - 1; for(index = start; index < end; ++ index) { if(data[index] < data[end]) { ++ small; if(small != index) Swap(&data[index], &data[small]); } } ++ small; Swap(&data[small], &data[end]); return small;}
0 0
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法 之 快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- 排序算法之快速排序
- lua5.1语法特性
- Xcode同时管理项目中的多个工程
- MVC中调用WEBAPI的方法
- 时间复杂度——均摊分析
- spring整合JMS - 基于ActiveMQ实现
- 排序算法之----快速排序算法
- IRQ中断控制
- ASP木马Webshell安全解决办案
- 关于QT的QFileDialog的使用
- NSString字符串初始化总结
- [management][health][TCM]
- 【markdown】markdown简单使用
- Android Button图片和文字都居左,且有一点间距
- N个色子的组合输出