class Main {
public static void QuickSort(int[] arr, int low, int high){
if(low<high){
int pivotIndex = partition(arr,low,high);
QuickSort(arr,pivotIndex+1,high);
QuickSort(arr,low,pivotIndex-1);
}
}
public static int partition(int[] arr, int low, int high) {
int pivot = arr[low];
int i = low+1;
int j = high;
while(true){
while(i<=j && arr[i]<=pivot){
i++;
}
while(i<=j && arr[j]>=pivot){
j--;
}
if(i >= j){
break;
}
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
int temp = arr[low];
arr[low] = arr[j];
arr[j] = temp;
return j;
}
public static void main(String[] args) {
int[] arr = {2,1,5,7,1,2,5,71,12,6,12};
QuickSort(arr,0,arr.length-1);
for(int num:arr){
System.out.print(num+" ");
}
}
}