MERGE - if(right>left) { m=(left+right)/2;...

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;  {   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 DocumentRight 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&gt;left) { m=(left+right)/2; mergesort(left,m); mergesort(m+1,right); simplemerge(left,m+1,right); } } void main() { int n,i; clrscr(); printf(&quot;Enter the no of data:&quot;); scanf(&quot;%d&quot;,&amp;n); printf(&quot;Enter the nos&quot;); for(i=0;i&lt;n;i++) scanf(&quot;%d&quot;,&amp;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

Page1 / 3

MERGE - if(right&amp;amp;gt;left) { m=(left+right)/2;...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online