本人独立域名One Coder博客:http://www.coderli.com
转载请务必注明出处:One Coder - http://www.coderli.com/archives/quick-sort
- package lhz.algorithm.chapter.seven;
-
-
-
* 本文地址:http://mushiqianmeng.blog.51cto.com/3970029/747858
-
-
- public class QuickSort {
-
-
- private static int[] input = new int[] { 2, 1, 5, 4, 9, 8, 6, 7, 10, 3 };
-
- public static void main(String[] args) {
-
- quickSort(input, 0, input.length - 1);
-
- printArray();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private static void quickSort(int[] array, int from, int to) {
- if (from < to) {
- int temp = array[to];
- int i = from - 1;
- for (int j = from; j < to; j++) {
- if (array[j] <= temp) {
- i++;
- int tempValue = array[j];
- array[j] = array[i];
- array[i] = tempValue;
- }
- }
- array[to] = array[i+1];
- array[i+1] = temp;
- quickSort(array, from, i);
- quickSort(array, i + 1, to);
- }
- }
-
- private static void printArray() {
- for (int i : input) {
- System.out.print(i + " ");
- }
- }
- }
本人独立域名One Coder博客:http://www.coderli.com
转载请务必注明出处:One Coder - http://www.coderli.com/archives/quick-sort
本文转自mushiqianmeng 51CTO博客,原文链接:http://blog.51cto.com/mushiqianmeng/747858,如需转载请自行联系原作者