1 //数组中两个数的交换
2 static void swap(int[] nums, int pos1, int pos2){
3 int temp = nums[pos1];
4 nums[pos1] = nums[pos2];
5 nums[pos2] = temp;
6 }
7 /**
8 * 快速排序中,在数组中选择一个数字,将数组中的数字分为两部分
9 * start, end 介于 0 与 nums.length之间
10 */
11 static int partition(int[] nums, int start, int end){
12
13 int index = new Random().nextInt(end + 1 - start) + start;//范围是[start end]闭区间
14 swap(nums, index, end);
15
16 int small = start - 1;
17 for (index = start; index < end; ++index) {
18
19 if (nums[index] < nums[end]) {
20 ++small;
21 if (small != index) {
22 swap(nums, index, small);
23 }
24 }
25
26 }
27
28 ++ small;
29 swap(nums, small, end);
30 return small;
31 }

最新文章

  1. Reverse-Daily(3)-DotNetCrackMe1
  2. 在Linux下用源码编译安装apache2
  3. 用Python和摄像头制作简单的延时摄影
  4. android中获取string字符串的方法
  5. 使用U盘安装Ubuntu系统的实践小结
  6. 第三章 传奇的开始--Delphi(附读书笔记)
  7. SQL viewId 比较好看的 Id
  8. python学习视频整理
  9. js 性能优化整理之 高频优化
  10. Jquery对话框基本配置
  11. iOS学习——自动定位
  12. [论文阅读] A Discriminative Feature Learning Approach for Deep Face Recognition (Center Loss)
  13. 解决win10 VC++6.0 应用程序无法正常运行 0xc0000142
  14. ReSharper2018破解详细方法
  15. [Swift]LeetCode858. 镜面反射 | Mirror Reflection
  16. python3 第二十九章 - 内置函数之tuple相关
  17. scrapy模拟用户登录
  18. Ant+Jmeter自动化接口测试的部署 及 部署过程中的坑
  19. HDU 1251 统计难题(Trie)
  20. 【原创】Nginx+PHP-FPM优化技巧总结(转)

热门文章

  1. 计算机毕业设计选题大合集,含ssm,springboot,小程序,php,python
  2. 【16位RAW图像处理三】直方图均衡化及局部直方图均衡用于16位图像的细节增强。
  3. [源码解析] 深度学习分布式训练框架 horovod (18) --- kubeflow tf-operator
  4. Python (paramiko) 连接Linux服务器
  5. 【剑指offer】55 - I. 二叉树的深度
  6. 【连载】微服务网格Istio(一)
  7. 【LeetCode】142. 环形链表 II
  8. 最大网络流dinic
  9. Springboot中mybatis执行逻辑源码分析
  10. 异地远程访问群晖NAS中的文件