Java Quick Sort quickSort(int[] arr, int left, int right)

Here you can find the source of quickSort(int[] arr, int left, int right)

Description

quick Sort

License

Open Source License

Declaration

public static int[] quickSort(int[] arr, int left, int right) 

Method Source Code

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

public class Main {

    public static int[] quickSort(int[] arr, int left, int right) {
        int dp;/*from   ww w  .  j  av  a 2 s  . c  o  m*/
        if (left < right) {
            dp = partition(arr, left, right);
            quickSort(arr, left, dp - 1);
            quickSort(arr, dp + 1, right);
        }
        return arr;
    }

    public static int partition(int n[], int left, int right) {
        int pivot = n[left];
        while (left < right) {
            while (left < right && n[right] >= pivot)
                right--;
            if (left < right)
                n[left++] = n[right];
            while (left < right && n[left] <= pivot)
                left++;
            if (left < right)
                n[right--] = n[left];
        }
        n[left] = pivot;
        return left;
    }
}

Related

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