Quick Sort'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public void quickSort(int[] arr, int low, int high){
if(low>high) return;
int i = low, int j = high, base = arr[low];
while(i < j){
while(arr[i]<base && i<j){i++;}
while(arr[j]>base && i < j){ j--;}
//after that the order is messy
swap(arr, low, j);
}
swap(arr, base, j);
quickSort(arr, low, j-1);
quickSort(arr, j+1, high);
}

private void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = tamp;
}