#include<stdio.h> #include<conio.h> void mergesort(int [],int,int); void merge(int [],int,int,int); void main() { int ar[30],p,n,r,i; clrscr(); printf("\n enter the size of array \n"); scanf("%d",&n); printf("\n enter the values of array \n"); for(i=1;i<=n;i++) { scanf("%d",&ar[i]); } p=1; r=n; mergesort(ar,p,r); printf("AFTER SORTING \n"); for(i=1;i<=r;i++) { printf("%d \n",ar[i]); } getch(); } void mergesort(int ar[],int p,int r) { int q; if(p<r) { q=(p+r)/2; mergesort(ar,p,q); mergesort(ar,q+1,r); merge(ar,p,q,r); ...

Read More »## Program for Merge Sort in C

Merge Sort: This is a program for merge sort in c #include"stdio.h" #include"stdlib.h" #define MAX 10000 void mergesort(int [],int,int); //Module for conquer and combine step of merge sort void merge(int a[],int p,int q,int r){ int k,n1,n2,l[MAX],m[MAX],i,j; n1=q-p+1; n2=r-q; for(i=1;i<=n1;i++) { l[i]=a[p+i-1]; } for(j=1;j<=n2;j++) m[j]=a[q+j]; l[n1+1]=32000; m[n2+1]=32000; i=1;j=1; for(k=p;k<=r;k++) { if(l[i]<=m[j]) { a[k]=l[i]; i++; } else { a[k]=m[j]; j++; } } ...

Read More »