void mergesort(int* arr, int left, int right)
{
if (right - left < 2) return ;
int mid = (right - left) / 2 + left;
mergesort(arr, left, mid);
mergesort(arr, mid, right);
merge(arr, left, mid, right);
}
void merge(int* arr, int left, int mid, int right)
{
int* A = arr + left;
int lb = mid - left; int* B = new int[lb + 1];
int lc = right - mid; int* C = arr + mid;
for (int i = 0; i < lb; B[i] = A[i++]);
for (int i = 0, j = 0, k = 0; j < lb;)
{
if (k < lc && C[k] < B[j])
A[i++] = C[k++];
if (lc <= k || B[j] <= C[k])
A[i++] = B[j++];
}
Print(arr);
printf("\n");
delete[] B;
}