package com.algorithms.sorting;


public class Quick {

    public void sort(Comparable[] a) { sort(a, 0, a.length-1); }

    private static void sort(Comparable[] a, int lo, int hi) {
        if (hi <= lo) return;
        int part = partition(a, lo, hi);
        sort(a, lo, part-1);
        sort(a, part+1, hi);
    }

    private static int partition(Comparable[] a, int lo, int hi) {
        int i = lo, j = j = hi+1;
        while (true) {
            while (less(a[++i], a[lo])) if (i == hi) break;
            while (less(a[lo], a[--j])) if (j == lo) break;

            if (i >= j) break;
            exch(a, i , j);
        }

        exch(a, lo, j);
        return j;
    }

    private static boolean less(Comparable v, Comparable w) {
        return v.compareTo(w) < 0;
    }

    private static void exch(Comparable[] a, int i, int j) {
        Comparable swap = a[i];
        a[i] = a[j];
        a[j] = swap;
    }
}

@@ -26,16 +26,58 @@
 rting;%0A%0A
+import edu.princeton.cs.algs4.StdRandom;%0A%0A
 %0Apublic 
@@ -129,16 +129,54 @@
 e%5B%5D a) %7B
+%0A        StdRandom.shuffle(a);%0A       
  sort(a,
@@ -187,20 +187,26 @@
 a.length
--1);
+ - 1);%0A   
  %7D%0A%0A    
@@ -359,17 +359,19 @@
 lo, part
--
+ - 
 1);%0A    
@@ -386,17 +386,19 @@
 (a, part
-+
+ + 
 1, hi);%0A
@@ -501,17 +501,19 @@
 = j = hi
-+
+ + 
 1;%0A     
@@ -703,17 +703,16 @@
 xch(a, i
- 
 , j);%0A  

Add shuffling to Quicksort