private fun partition(a: IntArray, left: Int, right: Int): Int { var left = left var right = right val pivot = a[left + (right - left) / 2] while (left <= right) { while (a[left] > pivot) left++ while (a[right] < pivot) right-- if (left <= right) { val temp = a[left] a[left] = a[right] a[right] = temp left++ right-- } } return left }
Choose mid value as pivot Move two pointers Swap and move on Return left pointer