Sure! Here's a randomized quicksort algorithm in C++ to sort an array of unsorted integers: ```cpp #include #include #include using namespace std; // Function to swap two elements void swap(int& a, int& b) { int temp = a; a = b; b = temp; } // Partition function for randomized quicksort int partition(int arr[], int low, int high) { int pivotIndex = low + rand() % (high - low + 1); int pivot = arr[pivotIndex]; swap(arr[pivotIndex], arr[high]); int i = low - 1; for (int j = low; j <= high - 1; j++) { if (arr[j] < pivot) { i++; swap(arr[i], arr[j]); } } swap(arr[i + 1], arr[high]); return i + 1; } // Randomized Quicksort function void randomizedQuicksort(int arr[], int low, int high) { if (low < high) { int pi = partition(arr, low, high); randomizedQuicksort(arr, low, pi - 1); randomizedQuicksort(arr, pi + 1, high); } } int main() { int arr[] = {10, 7, 8, 9, 1, 5}; int size = sizeof(arr) / sizeof(arr[0]); cout << "Original array: "; for (int i = 0; i < size; i++) { cout << arr[i] << " "; } cout << endl; srand(time(NULL)); // Seed the random number generator randomizedQuicksort(arr, 0, size - 1); cout << "Sorted array: "; for (int i = 0; i < size; i++) { cout << arr[i] << " "; } cout << endl; return 0; } ``` The `randomizedQuicksort` function is similar to the regular quicksort but with a random pivot selection. Instead of always choosing the last element as the pivot, it selects a random element within the subarray, swapping it with the last element, and then proceeds with the partitioning and sorting. For the given example array `{10, 7, 8, 9, 1, 5}`, the output will be `1 5 7 8 9 10` after