Quicksort?
void QuickSort(int[] arr, int low, int high)
if (low < high)
Follow on:
int pi = Partition(arr, low, high);
QuickSort(arr, low, pi - 1);
QuickSort(arr, pi + 1, high);
int Partition(int[] arr, int low, int high)
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++)
if (arr[j] < pivot)
i++;
(arr[i], arr[j]) = (arr[j], arr[i]);
(arr[i + 1], arr[high]) = (arr[high], arr[i + 1]);
return i + 1;
Explanation:
Choose last element as pivot, partition array so left < pivot < right, recursively sort
subarrays.