Friday, June 14, 2019

Insertion sort Program in C -Data Structure





( In-place sort and is stable . It has n*(n-1)/2 comparision as in this sort )

#include<stdio.h>
#include<conio.h>
void main()
{
int a[25],temp,n,i,j;
clrscr();
printf(“enter array size”);
scanf(“%d”,&n);
printf(“enter array data”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=0;i<n-1;i++)
{
j=1;
while(j>0 && a[j-1]>a[j])
{
temp = a[j];
a[j]=a[j-1];
a[j-1]=temp;
j--;
}
}
printf(“result \n\n”);
printf(“\n%d”,a[i]);

 PROGRAMS:-

For many other Language  Programs related to microprocessor 8086, C++ ,  and DataStructures , etc visit our  BLOG

There are programs of largest ,smallest ,division ,multiplication,odd/even,block operation ,string operations ,etc


No comments:

Post a Comment