Please look at the above code
#include<stdio.h>
#include<stdlib.h>
void mergesort(int *,int ,int);
void merge1(int *,int ,int ,int);
int main()
{
int low=0,high,n,i,a[100];
printf("Enter the lenght of array\n");
scanf("%d",&n);
high =n-1;
printf("Enter the array that you want to sort\n");
for(i=low;i<=high;i++)
{
scanf("%d",&a[i]);
}
mergesort(a,low,high);
printf("The sorted array is \n");
for(i=low;i<=high;i++)
{
printf("%d-",a[i]);
}
printf("MERGE sorted");
return 0;
}
void mergesort(int a[],int low,int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge1(a,low,mid,high);
}
}
void merge1(int a[],int low,int mid,int high)
{
int i=low,j=mid+1,new_array[100],k=low,m;
while(i<=mid && j<=high)
{
if(a[i]<a[j])
{
new_array[k]=a[i];
i++;
k++;
}
else
{
new_array[k]=a[j];
j++;
k++;
}
}
while(i<=mid)
{
new_array[k]=a[i];
i++;k++;
}
while(j<=high)
{
new_array[k]=a[j];
j++;
k++;
}
for(m=low;m<=high;m++)
{
a[m]=new_array[m];
}
}
Actually, I implemented merge sort and it is working fine but I want much better code than this . Can anyone make this code much better?