write me a partition function in cpp which rearranges its elements in such a way that the value of the element in k-th position is in the position the value would be in a sorted array. In the partitioned array, all elements before the k-th element are less than or equal to that element, and all the elements after the k-th element are greater than or equal to that element
 Here is a possible implementation of the partition function in C++ using the QuickSelect algorithm:
```
void partition(int arr[], int n, int k) {
    int left = 0, right = n - 1;
    while (true) {
        int pivotIndex = (left + right) / 2;
        int pivotValue = arr[pivotIndex];
        swap(arr[pivotIndex], arr[right]);
        int storeIndex = left;
        for (int i = left; i < right; i++) {
            if (arr[i] < pivotValue) {
                swap(arr[storeIndex], arr[i]);
                storeIndex++;
            }
        }
        swap(arr[right], arr[storeIndex]);
        if (storeIndex == k) {
            return;
        } else if (storeIndex < k) {
            left = storeIndex + 1;
        } else {
            right = storeIndex - 1;
        }
    }
}
```
This function takes an array `arr` of integers, its size `n`, and the position `k` as input. It rearranges the elements in the array such that the element in the k-th position is in the position it would be in a sorted array. The elements before
  Sure! Here is an example of a partition function in C++ that rearranges its elements in the way you described:
```
#include <iostream>
using namespace std;

void partition(int arr[], int low, int high) {
  // Split the array around the k-th element
  int k = low;
  int i = low + 1;
  for (int j = low + 1; j <= high; j++) {
    if (arr[j] <= arr[k]) {
      i++;
      swap(arr[i], arr[j]);
    }
  }
  swap(arr[k], arr[i - 1]);
}

int main() {
  int arr[5] = {3, 2, 7, 1, 4};
  int n = sizeof(arr) / sizeof(arr[0]);
  int k = 3; // The element to partition around

  partition(arr, 0, n - 1);

  // Print the sorted array
  for (int i = 0; i < n; i++) {
    cout << arr[i] << " ";
  }

  return 0;
}
```
In this example, we use the `partition` function to split the array around the `k