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

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

#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];

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

View Full Document
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;
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

Page1 / 3

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

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

View Full Document
Ask a homework question - tutors are online