Aim: - To implement Insertion Sort.

  

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

 

void insert(int [],int); void main()

{

int a[20],i,n;

clrscr();

printf("Enter the number of items in the array"); scanf("%d",&n);

printf("Enter the data in the array"); for(i=0;i<n;i++)

{

scanf("%d",&a[i]);

}

insert(a,n);

getch();

}

 void insert(int a[],int n)

{

int i,j,temp; for(i=1;i<n;i++)

{

temp=a[i];

for(j=i-1;j>=0;j--)

{

if(a[j]>temp)

{

a[j+1]=a[j];

}

else break;

}

a[j+1]=temp;

}

printf("Data After Insertion Sort"); for(i=0;i<n;i++) printf("\n%d",a[i]);

 }