Java Quick Sort quickSort(int[] a, int start, int end)

Here you can find the source of quickSort(int[] a, int start, int end)

Description

quick Sort

License

Open Source License

Declaration

public static void quickSort(int[] a, int start, int end) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static void quickSort(int[] a, int start, int end) {
        int length = end - start + 1;
        System.out.println(String.format("start:%s, end:%s, length:%s ", start, end, length));
        if (length <= 1) {
            return;
        }/*from   w  w  w  .j a  v  a2s .co m*/

        int b[] = new int[length];
        int k = 1, j = 0;
        for (int i = start + 1; i <= end; i++) {
            if (a[i] > a[start]) {
                b[length - k] = a[i];
                k++;
            } else {
                b[j] = a[i];
                j++;
            }
        }
        b[j] = a[start];
        System.arraycopy(b, 0, a, start, length);
        print(a, 0, a.length);
        if (length == 2) {
            return;
        }

        quickSort(a, start, start + j - 1);
        quickSort(a, start + j + 1, end);
    }

    public static void print(int a[], int start, int length) {
        for (int j = start; j < (start + length); j++) {
            System.out.print(a[j] + "\t");
        }
        System.out.println();
    }
}

Related

  1. quicksort(double[] main, int[] index)
  2. quicksort(final double[] array, final int[] index)
  3. quicksort(final long[] data, final int left, final int right)
  4. quicksort(float[] a, int[] index, int left, int right)
  5. quickSort(int[] a)
  6. quickSort(int[] a, int start, int end, int[] p)
  7. quickSort(int[] arr, int left, int right)
  8. quickSort(int[] array)
  9. quicksort(int[] array)