Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
This repository was archived by the owner on Sep 7, 2025. It is now read-only.

Gh #505

@ultimozz

Description

@ultimozz

#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");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions