{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MERGE - if(right>left m=(left right/2 mergesort(left,m...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> /* RISHI AGARWAL           MERGE SORT    ROLL NO 02    SE CMPN A */ #define max 10 int a[max]; void display(int n) {  int i;  printf("\nLIST\n");  for(i=0;i<n;i++)  printf("%d ",a[i]); } void simplemerge(int f,int s,int t) {  int i,j,k,w,auxi[max];  i=f;  j=s;  k=-1;  while(i<=s-1&&j<=t)  {   if(a[i]<a[j])   auxi[++k]=a[i++];   else   auxi[++k]=a[j++];  }  for(w=i;w<s;w++)  auxi[++k]=a[w];
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
 for(w=j;w<=t;w++)  auxi[++k]=a[w];  for(w=0;w<=k;w++)  a[f+w]=auxi[w]; } void mergesort(int left,int right) {  int m;
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if(right>left) { m=(left+right)/2; mergesort(left,m); mergesort(m+1,right); simplemerge(left,m+1,right); } } void main() { int n,i; clrscr(); printf("Enter the no of data:"); scanf("%d",&n); printf("Enter the nos"); for(i=0;i<n;i++) scanf("%d",&a[i]); //Displaying List display(n); //Merge Sort mergesort(0,n-1); //Displaying Sorted List display(n); getch(); } OUTPUT: Enter the no of data:5 Enter the nos5 4 3 2 1 LIST 5 4 3 2 1 LIST 1 2 3 4 5...
View Full Document

{[ snackBarMessage ]}