#include <iostream>
#include <vector>
using namespace std;
void merge(int arr[],int L,int mid,int R)
{
int *help = new int(R-L+1);
int p1=L,p2=mid+1,i=0;
while(p1<=mid && p2<=R)
{
help[i++] = arr[p1]>arr[p2] ? arr[p2++] : arr[p1++];
}
while(p1<=mid)
help[i++] = arr[p1++];
while(p2<=R)
help[i++] = arr[p2++];
for (int i=0;i<R-L+1;i++)
{
arr[L+i] = help[i];
}
}
void MergeSort(int arr[],int L,int R)
{
if (L < R)
{
int mid = L + ((R-L)>>2); // (L+R)/2
MergeSort(arr,L,mid);
MergeSort(arr,mid+1,R);
merge(arr,L,mid,R);
}
}
int main()
{
int arr[7]={6, 8, 3, 2, 5, 1, 7};
MergeSort(arr,0,6);
for(int i=i;i<7;++i)
cout<<arr[i]<<endl;
//system("pause");
return 0;
}