Professional Documents
Culture Documents
h>
void mergesort(int a[], int lb, int ub)
{
int mid;
if(lb<ub)
{
mid = (lb+ub)/2;
}
}
else
{
temp[z] = a[y];
y++;
z++;
}
}
while(x <= mid)
{
temp[z] = a[x];
x++;
z++;
}
while(y <= ub)
{
temp[z] = a[y];
y++;
z++;
}
mergesort(a, 0, n-1);
printf("the sorted array is \n");
for(int j = 0; j<n; j++)
{
printf("%d ", a[j]);
}
}
************************************************************************
#include<stdio.h>
#define n 6
int a[6]={9,8,7,6,5,10};
int temp[6];
void mergesort(int lb, int ub)
{
int mid;
if(lb<ub)
{
mid = (lb+ub)/2;
mergesort(lb, mid);
mergesort(mid+1, ub);
merge(lb, mid, ub);
}
else
return;
}
else
{
temp[z] = a[y];
y++;
z++;
}
}
while(x <= mid)
{
temp[z] = a[x];
x++;
z++;
}
while(y <= ub)
{
temp[z] = a[y];
y++;
z++;
}
mergesort(0, n-1);
printf("the sorted array is \n");
for(int j = 0; j<n; j++)
{
printf("%d ", a[j]);
}
}