| 10 | arr[y] = temp; |
| 11 | } |
| 12 | static int partition(int[] arr, int st, int end){ |
| 13 | int pivot = arr[st]; |
| 14 | int cnt = 0; |
| 15 | for(int i = st+1; i <= end; i++){ |
| 16 | if(arr[i] <= pivot) cnt++; |
| 17 | } |
| 18 | int pivotIdx = st + cnt; |
| 19 | swap(arr, st, pivotIdx); |
| 20 | int i = st, j = end; |
| 21 | while(i < pivotIdx && j > pivotIdx){ |
| 22 | while (arr[i] <= pivot) i++; |
| 23 | while (arr[j] > pivot) j--; |
| 24 | if(i < pivotIdx && j > pivotIdx){ |
| 25 | swap(arr, i, j); |
| 26 | i++; |
| 27 | j--; |
| 28 | } |
| 29 | } |
| 30 | return pivotIdx; |
| 31 | } |
| 32 | static void quickSort(int[] arr, int st, int end){ |
| 33 | if(st >= end) return; |
| 34 | int pi = partition(arr, st, end); |