You are on page 1of 3

Write a program to implement merge sort..

#include<stdio.h>

#include<conio.h>

#define SIZE 6

int arr[SIZE];

void merg_sort(int[],int,int);

void merg_pass(int[],int,int,int);

void main()

int i,l,h;

printf("enter values");

for(i=0;i<SIZE;i++)

scanf("%d",&arr[i]);

l=0;

h=SIZE-1;

merg_sort(arr,l,h);

for(i=0;i<SIZE;i++)

printf("%d\t",arr[i]);

getch();

void merg_sort(int arr[],int l,int h)

int mid;

if(l!=h)

Rachit Aggrawal(0809113056)
mid=(l+h)/2;

merg_sort(arr,l,mid);

merg_sort(arr,mid+1,h);

merg_pass(arr,l,mid,h);

void merg_pass(int arr[],int bottom,int size,int upper)

int r,s,f,t,i,temp[100];

f=bottom;

r=size;

t=bottom;

s=size+1;

while(f<=r&&s<=upper)

if(arr[f]<arr[s])

temp[t]=arr[f];

f++;

else

temp[t]=arr[s];

s++;

t++;

Rachit Aggrawal(0809113056)
}

for(f=f;f<=r;f++)

temp[t]=arr[f];

t++;

for(s=s;s<=upper;s++)

temp[t]=arr[s];

t++;

for(i=bottom;i<=upper;i++)

arr[i]=temp[i];

Rachit Aggrawal(0809113056)

You might also like