public class quickSort { public static void main(String[] args) { int[] myArray = (3,2,5,4,1}; quicksort(myArray,1,3); for (int i = 0; i < myArray.length; i++) { system.out.printf("d,",myArray[i]); } } public static void quicksort (int[] a) { quicksort(a, 0, a.length-1); } private static void quicksort (int[] a, int l, int r) { if (l>=r) //list is empty return; //recursion step: make partition and sort recursively int m = partition(a, l, r); quicksort(a,l,m-1); quicksort(a,m+1,r); } //partition the array from l+1 to r with pivot a[l] private static int partition (int[] a, int l, int r) { int i=l+1; //pointer on left side int j=r; //pointer on right side int p = a[l]; //pivot element //move pointer to center or swap if on wrong sides while (i<=j) { if (a[i]<=p) i++; else if (a[j]>p) j--; else swap(a,i,j); } //swap pivot element between partitions swap(a,l,j); //return position of pivot element return j; } //swap two elements in the array private static void swap (int[] a, int i, int j) { int h = a[i]; a[i] = a[j]; a[j] = h; } }