#include<stdio.h>
#define maxsize 10
void Merge(int arr[],int low, int mid, int high)
{
int B[maxsize];
int i,j,k;
for(i=low;i<=high;i++)
{
B[i] = arr[i];
}
for(i=low, j=mid+1, k=low; i<=mid && j<=high;k++)
{
if(B[i]<=B[j])
{
arr[k] = B[i++];
}
else
{
for(int m=i;m<=mid;m++)
{
printf("逆序对:(%d, %d)\n", B[m], B[j]);
}
arr[k] = B[j++];
}
}
while(i<=mid)
{
arr[k++] = B[i++];
}
while(j<=high)
{
arr[k++] = B[j++];
}
}
void MergeSort(int arr[], int low, int high)
{
if(low<high)
{
int mid = (high+low)/2;
MergeSort(arr, low, mid);
MergeSort(arr, mid+1, high);
Merge(arr, low, mid, high);
}
}
int main()
{
int arr[maxsize]={2,4,3,1,5,6};
int low = 0, high = 4;
MergeSort(arr, low, high);
}