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 )
-
Asus G73 Gaming Rog nVidia GeForce GTX 3D graphics with 460 offers 1.5 GB of GDDR5 memory and supports NVIDIA 3D Vision, and comes with N...
-
G reen Turtle Tortoise Optical Mouse sells Source Square, and we would say that is good for young girls and children just learning to use ...
-
NAIL CARE : The color of the nails is indicators of good health or sickness. Healthy nails are transparent and look a little rosy becaus...
-
Healthy glowing hair is a crowning glory for a woman today. To keep it this way is not very simple given to-days living conditions. The h...
-
It is said that the shape of the eyebrows change one`s complexion in a good way, and it is true indeed. If you give them a nice shape, yo...