IMPLEMENTATION OF MERGE SORT
PROGRAM:
#include
#include
#include
int n;
void main()
{
int i,low,high;
int a[20];
void mergesort(int a[10],int low,int high);
void display(int a[10]);
clrscr();
printf("\n\tMerge Sort");
printf("\n Enter the size of elements");
scanf("%d",&n);
printf("\n Enter the list element");
for(i=0;i
low=0;
high=n-1;
mergesort(a,low,high);
display(a);
getch();
}
void mergesort(int a[10],int low,int high)
{
int mid;
void combine(int a[10],int low,int mid,int high);
if(low
mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
combine(a,low,mid,high);
}
}
void combine(int a[10],int low,int mid,int high)
{
int i,j,k;
int temp[10];
k=low;
i=low;
j=mid+1;
while(i<=mid&&j<=high)
{
if(a[i]<=a[j])
{
temp[k]=a[i];
i++;
k++;
}
else
{
temp[k]=a[j];
j++;
k++;
}
}
while(i<=mid)
{
temp[k]=a[i];
i++;
k++;
}
while(j<=high)
{
temp[k]=a[j];
j++;
k++;
}
for(k=low;k<=high;k++)
a[k]=temp[k];
}
void display(int a[10])
{
int i;
printf("\n\n The Sorted Array is.......");
for(i=0;i
}
OUTPUT:
Merge Sort
Enter the size of elements 5
Enter the list element
9
8
7
6
5
The Sorted Array is.......5 6 7 8 9
CIET college Programs,LAB Programs for Engineering Students,DAA LAB Programs,DSA LAB Programs,Remoboys,karthik,Remokn,Student3k,programs source code,Design Analysis And Algorithms LAB Programs,Data Structures and Algorithms LAB Programs,LAB Codings,Coimbatore Institute of Engineering and Technology ( CIET )
Wednesday, September 22, 2010
IMPLEMENTATION OF MERGE SORT
9:24 AM
Karthikh Venkat
Popular Posts( Last 7 Days )
-
wwe wallpapers,wwe stills, wwe posters,wwe latest picture photo posters collections, batista latest pictures wallpapers posters news recent
-
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Computer science and engineering department aims at producing technically competent professi...
-
A Aalim Muhammed Salegh College of Engineering, Chennai Aarupadai Veedu Institute of Technology, Kanchipuram Aksheyaa College of Engineer...
-
Tapsee Photo Shoot, aadukalam actress tapasee pannu new stills, south indian actress tapsee pannu new stills, tapasee pannu Latest Ph...
-
Ravi Teja's Veera Movie Stills stars : Ravi Teja, Kajal, Taapsee, Kick Shaam, Sridevi, Prakash Raj, Brahmanandam directed by Ramesh Varm...
-
Pak match-fixing scandal: Handed over 'proof' of Asif's corruption, says Veena Malik Lahore: Pakistani cri...