快排非递归
来源:互联网 发布:unity3d格式 解包 编辑:程序博客网 时间:2024/06/07 19:55
private static void nonRec_quickSort(int[] a,int start,int end) { LinkedList<Integer> stack = new LinkedList<Integer>(); //用栈模拟 if(start < end) { stack.push(end); stack.push(start); while(!stack.isEmpty()) { int l = stack.pop(); int r = stack.pop(); int index = partition(a, l, r); if(l < index - 1) { stack.push(index-1); stack.push(l); } if(r > index + 1) { stack.push(r); stack.push(index+1); } } } } private static int partition(int[] a, int start, int end) { int pivot = a[start]; while(start < end) { while(start < end && a[end] >= pivot) end--; a[start] = a[end]; while(start < end && a[start] <= pivot) start++; a[end] = a[start]; } a[start] = pivot; return start; }
阅读全文
0 0
- 快排非递归
- 快排非递归实现
- 快排非递归算法
- 快排非递归算法
- 快排非递归实现
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 递归
- 微信小程序支付 java
- 安装office2016后文档表格不能显示图标
- trafodion sqlci (core dumped)
- Java高级篇(四一)------Servlet生命周期
- linux复制指定目录下的全部文件到另一个目录中,linux cp 文件夹
- 快排非递归
- 求学之道
- 对redis的理解
- OpenResty 限制下载速度
- make mattest 报错 _ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputA
- 免安装版mysql环境变量配置
- windows安全对象学习
- String.Empty ,String=“”和null的区别
- jsp中frameset的使用