#include <stdio.h>
#include <stdlib.h>
void G_qsort(int *a,int first,int mid,int last,int *temp)
{
int n = mid,m = last;
int k = 0;
int i = first,j = mid+1;
while(i <= n && j <= m)
{
if(a[i] <= a[j])
{
temp[k++] = a[i++];
}
else
{
temp[k++] = a[j++];
}
}
while(i <= n)
{
temp[k++] = a[i++];
}
while(j <= m)
{
temp[k++] = a[j++];
}
for(i = 0; i < k; i++)
{
a[first+i] = temp[i];
}
}
void G_sort(int *a,int first,int last,int *temp)
{
if(first < last)
{
int mid = (first+last)/2;
G_sort(a,first,mid,temp);
G_sort(a,mid+1,last,temp);
G_qsort(a,first,mid,last,temp);
}
}
int sort(int *a,int n)
{
int *p = malloc(n);
if(p == NULL)
{
return -1;
}
else
{
free(p);
G_sort(a,0,n-1,p);
p = NULL;
return 1;
}
}
int main()
{
int a[8]={8,4,5,7,1,3,6,2};
int i;
sort(a,8);
for(i = 0; i < 8; i++)
{
printf("%d",a[i]);
}
printf("\n");
return 0;
}