排序
来源:互联网 发布:ubuntu 16.04合理分区 编辑:程序博客网 时间:2024/06/07 05:02
一、快排
int getRandom(int start, int end) { srand((int)time(0)); int idx = random() % (end - start + 1) + start; return idx;}int partition(int *a, int len, int start, int end) { int idx = getRandom(start, end); if (idx != end) { swap(a[idx], a[end]); } int small = start - 1; for (idx = start; idx < end; ++ idx) { if (a[idx] < a[end]) { ++ small; if (small != idx) { swap(a[idx], a[small]); } } } ++ small; swap(a[small], a[end]); return small;}void quitSort(int *a, int len, int start, int end) { if (start == end) { return; } int idx = partition(a, len, start, end); if (idx > start) { quitSort(a, len, start, idx - 1); } if (idx < end) { quitSort(a, len, idx + 1, end); }}void myQuitSort(int *a, int len) { quitSort(a, len, 0, len - 1);}
0 0
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 每天laravel-20160706|KeyForgotten
- Android学习笔记----解决“com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536”问题
- activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示
- C#点击按钮后其他按钮排列类似导航菜单
- GPG入门
- 排序
- java中去掉html标签
- 详解SQL Server连接(内连接、外连接、交叉连接)
- js cookie 的增删改查
- PHP格式化数组输出样式
- 大端小端
- JQuery_验证时间段,起始时间必须小于截至时间 JQuery插件
- C++之类的比较运算符的重载
- IOS 三维图像处理(九)--CATransform3D