#include <stdio.h>
int main () {
int a[7] = {49,38,65,97,76,13,27};
Mergesort(a,7,0,6);
print_arr(a,7);
return 0;
}
void print_arr(int a[], int n){
for(int i = 0 ; i < n ; i++){
printf("%d ",a[i]);
}
printf("\n");
}
void Merge(int a[],int n,int low,int mid ,int high){
int b[n];
int i,j,k;
for(i = low ; i <= high ; i++){
b[i] = a[i];
}
for(i = low,j = mid+1,k = i ; i <= mid&&j <= high;k++ ){
if(b[i] > b[j]){
a[k] = b[j++];
}else {
a[k] = b[i++];
}
}
while(i<=mid)a[k++] = b[i++];
while(j<=high)a[k++] = b[j++];
}
void Mergesort(int a[],int n,int low,int high){
if(low < high){
int mid = (low+high)/2;
Mergesort(a,n,low,mid);
Mergesort(a,n,mid+1,high);
Merge(a,n,low,mid,high);
print_arr(a,n);
}
}