merges(int a[],int l,int r)
{
int c=(l+r)/2,i=l;
int j=c+1,k=0,x;
int b[r-l+1];
while(j<=r && i<=c)
{
if(a[j]<a[i])
b[k++]=a[j++];
else
b[k++]=a[i++];
}
while(j<=r)
b[k++]=a[j++];
while(i<=r)
b[k++]=a[i++];
for(x=l;x<=r;x++)
a[x]=b[x-l];
}
merge_rec(int a[],int l,int r)
{
int c;
if(l<r)
{
c=(l+r)/2;
merge_rec(a,l,c);
merge_rec(a,c+1,r);
merges(a,l,r);
}
}
int main()
{
int a[]={1,4,2,11,0,45,9,75,-4,40};
int i;
merge_rec(a,0,9);
for(i=0;i<=9;i++)
{
printf("%d ",a[i]);
}
getch();
}
This blog will cover all important aspects of 'C' 'C++', 'Data Structures in C' and other Technical stuffs. In this blog you will find good C Interview Questions Answers. I will be posting both multiple choice and subjective type C interview questions and answers. Tutorials will be posted from time to time that will focus on problem solving.
Sunday, October 2, 2011
Merge Sort C program for Dev c++
Labels:
sorting
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment