C code snippet for merging sort algorithm to sort
Code Snippet:
#include<stdio.h>
#include<conio.h>
int j,a[15],i,temp,n;
void main()
{
clrscr();
void createheap(int);
printf(\"Enter number of elements\n(Not more than 15) \");
scanf(\"%d\",&n);
for(i=1;i<=n;i++)
scanf(\"%d\",&a[i]);
for(i=n;i>=2;i--)
createheap(i);
for(i=n-1;i>=1;i--)
{
temp=a[1];
a[1]=a[i+1];
a[i+1]=temp;
for(j=i;j>=2;j--)
createheap(j);
}
printf(\"The sorted elements are :\n\");
for(i=1;i<=n;i++)
printf(\"%d \",a[i]);
getch();
}
void createheap(int y)
{
if(y>1)
{
if(a[y]>a[y/2])
{
temp=a[y];
a[y]=a[y/2];
a[y/2]=temp;
createheap(y/2);
}}}
ActionScript - ActionScript 3 - Apache - AppleScript - ASP - Assembler - Bash - C - C# - C++ - ColdFusion - CSS - Delphi - DOS Batch - Fortran - HTML - iPhone - Java - JavaScript - jQuery - Lisp - MatLab - Maxscript - MXML - MySQL - Objective C - Other - Pascal - Perl - PHP - PL SQL - Prolog - Pseudocode - Python - Rails - SmallTalk - Smarty - SML - SPSS - SQL - SVN - Symfony - TCL - VB.NET - Visual Basic - XHTML - XML - XSLT
© 2000-2015 Xentrik.Net