快速排序
来源:互联网 发布:网络英语翻译 编辑:程序博客网 时间:2024/06/06 14:02
import java.util.*; public class QuickSort { public int[] quickSort(int[] A, int n) { quickSortRecurrence(A, 0, n - 1); return A; } public void quickSortRecurrence(int[] A, int start, int end){ System.out.println("[" + start + "," + end + "]" + (start < end)); if(start < end){ int mid = A[end]; int counter = start; for (int i = start; i < end; i++ ){ if(A[i] < mid){ swap(A, counter, i); counter = counter + 1; } } swap(A, counter, end); quickSortRecurrence(A, start, counter - 1); quickSortRecurrence(A, counter + 1, end); } } public boolean swap(int[] A, int n1, int n2){ if(n1 != n2){ int temp = A[n1]; A[n1] = A[n2]; A[n2] = temp; return true; } else { return false; } }}
阅读全文
1 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 一个不小心引发的Heap corruption
- MySQL入门--插入记录的时候NULL与NOT NULL
- 48. Rotate Image(数学矩阵相关知识)
- Python学习笔记(8) -- 多个数求和(关键词:reduce)
- C++ ---- 多字符编码与Unicode码
- 快速排序
- 把MyEclipse的工程导入到Eclipse中
- MySQL--唯一约束、自增约束、外键约束说明
- MySQL查询练习题
- C++算法学习——经典的抽象设计——charstack(2)
- Spark SQL入门
- LeetCode 17 Jump Game II
- Java基础-IO
- HDU 2438 Turn the corner(三分查找, 几何求解)