classSolution { public: //Function to sort an array using quick sort algorithm. voidquickSort(int arr[], int low, int high){ if(low >= high) return; int m = partition(arr, low, high); quickSort(arr, low, m - 1); quickSort(arr, m + 1, high); }
public: intpartition(int arr[], int low, int high){ int pivot = arr[high]; int l = low, r = high - 1; while(l <= r) { while(l <= r and arr[l] <= pivot) l++; while(l <= r and arr[r] >= pivot) r--; if(l <= r and arr[l] >= arr[r]) swap(arr[l++],arr[r--]); } swap(arr[l], arr[high]); return l; }