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 )
-
Kareena Kapoor at Sony Vaio Press Conference Kareena Kapoor at Sony Vaio Press Conference
-
wwe wallpapers,wwe stills, wwe posters,wwe latest picture photo posters collections, batista latest pictures wallpapers posters news recent
-
Vinnai Thandi Varuvaya ~ Blu ray ~ Quality ~ Movie Download This image has been resized. Click this bar to view the full image. The or...
-
Lord Vishnu Sleeping Hindu God Vishnu Blessing God Vishnu Smiling God Vishnu And Planets Lord Vishnu Standing On A Lotus ...
-
Lord Siva Siva Wallpapers,Pictures,Photos,Images 1 Siva Wallpapers,Pictures,Photos,Images 2 Siva Wallpapers,Pictures,Photos,Images ...