public class QuickSort {
public static void main(String[] args){
int length = 10;
int[] a = new int[length];
QuickSort qs = new QuickSort();
qs.quicksort(a, 0, length-1);
for(int i=0; i<length; i++) {
System.out.println(a[i]);
}
}
public void swap(int[] a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public int partition(int[] a, int low, int high) {
int pivot = a[low];
while(low<high) {
while(low<high && a[high]>=pivot) --high;
swap(a, low, high);
while(low<high && a[low]<=pivot) ++low;
swap(a, low, high);
}
return low;
}
public void quicksort(int a[], int low, int high) {
if(low<high){
int pivotloc = partiton(a, low, high);
quicksort(a, low, pivotloc-1);
quicksort(a, pivotloc+1, high);
}
}
}