You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
#include<stdio.h>
int a[100];
int mergesort(int low,int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
mergesort(low,mid);
mergesort(mid+1,high);
merge(low,mid,high);
}
}
int merge(int low,int mid,int high)
{
int h,i,j,b[100],k;
h=low;
i=low;
j=mid+1;
while(h<=mid && j<=high)
{
if(a[h]<=a[j])
{
b[i]=a[h];
h=h+1;
i=i+1;
}
else
{
b[i]=a[j];
j=j+1;
i=i+1;
}
}if(h>mid)
{
for(k=j;k<=high;k++)
{
b[i]=a[k];
i=i+1;
}
}
else
{
for(k=h;k<=mid;k++)
{
b[i]=a[k];
i=i+1;
}
}
for(k=low;k<=high;k++)
{
a[k]=b[k];
}
}
main()
{
int i,n,low,high;
system("clear");
printf("Enter the number of elements in the array");
scanf("%d",&n);
printf("Enter the array\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
low=1;
high=n;
mergesort(low,high);
printf("\nThe sorted array is:\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
printf("\n");
}