Write a Recursive function in ‘C’ to implement the merge sort on given set of integers.

Write a Recursive function in ‘C’ to implement the merge sort on given set of integers.


void merge (int low, int mid, int high)
{
int temp [MAX];
int i=low;
int j= mid+1;
int k= low;
while ((i<=mid)&&(j<=high))
{
if (array [i]<=array[j])
   temp [k+1]= array[i++];
else
   temp [k++] = array[j++];
}
     while(i<=mid)
temp[k++]=array[i++];
while(j<=high)
temp[k++]=array[j++];
for(i=low;i<=high;i++)
array[i]=temp[i];
}
void merge_sort(int low, int high)
{
int mid;
if(low!=high)
{
mid=(low+high)/2;
merge_sort(low,mid);
merge_sort(mid+1,high);
merge(low, mid, high);
}
}

Leave a Comment

error: Content is protected !!