(arr, low, high)
| 1 | def partition(arr, low, high): |
| 2 | i = low - 1 # index of smaller element |
| 3 | pivot = arr[high] # pivot |
| 4 | |
| 5 | for j in range(low, high): |
| 6 | # If current element is smaller than or |
| 7 | # equal to pivot |
| 8 | if arr[j] <= pivot: |
| 9 | # increment index of smaller element |
| 10 | i = i + 1 |
| 11 | arr[i], arr[j] = arr[j], arr[i] |
| 12 | |
| 13 | arr[i + 1], arr[high] = arr[high], arr[i + 1] |
| 14 | return i + 1 |
| 15 | |
| 16 | |
| 17 | # The main function that implements QuickSort |