clanguage07@gmail.com

clanguage07@gmail.com

Saturday, June 16, 2012

Write C program that implement the following sorting methods to sort a given list of integers in ascending order: i) Insertion sort

Program:

#include<stdio.h>
#include<conio.h>

void inst_sort(int []);

void main()
{
int num[5],count;
clrscr();
printf("\nEnter the Five Elements to sort:\n");

for (count=0;count<5;count++)
scanf("%d",&num[count]);
inst_sort(num);

printf("\n\nElements after sorting: \n");
for(count=0;count<5;count++)
printf("%d\n",num[count]);
getch();
}

// Function for Insertion Sorting
void inst_sort(int num[])
{
int i,j,k;
for(j=1;j<5;j++)
{
k=num[j];
for(i=j-1;i>=0 && k<num[i];i--)
num[i+1]=num[i];
num[i+1]=k;
}
}

No comments:

Post a Comment

GET MORE INFORMATION

http://ads.qadservice.com/t?id=c2168e05-8974-4816-872a-91936ff7379d&size=1024x768&drct=true