Instead of just swapping the elements, it would be more efficient to sort them directly. If an element from
arr1 is larger than one from arr2, one can assume that arr2[0] should be inserted into arr1, since it is the
smallest there.To paste the element from arr1 to arr2, you need to find a suitable place in arr2 before copying.
I propose the following declaration for the function :
void replace(int* arrx, int arr2[], int m);