0% found this document useful (0 votes)
4 views1 page

Insertion Sort Algorithm in C

The document contains a C program that implements the insertion sort algorithm. It prompts the user to enter the size and elements of an array, sorts the array using the insertion sort method, and then displays the sorted array. The code includes necessary functions and input/output operations for sorting and displaying the array elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Insertion Sort Algorithm in C

The document contains a C program that implements the insertion sort algorithm. It prompts the user to enter the size and elements of an array, sorts the array using the insertion sort method, and then displays the sorted array. The code includes necessary functions and input/output operations for sorting and displaying the array elements.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

---------------------------

INSERTION SORT
---------------------------
#include<stdio.h>
void insertion(int a[],int n)
{
int i,j,item;
for(i=1;i<n;i++)
{
item=a[i];
for(j=i-1;(j>=0)&&(a[j]>item);j--)
{
a[j+1]=a[j];
}
a[j+1]=item;
}
}
int main()
{
int a[60],i,n;

printf("\n enter the size of the array::");


scanf("%d",&n);
printf("\n enter the elements of the array::");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
insertion(a,n);
printf("\n display::");
for(i=0;i<n;i++)
{
printf("%4d",a[i]);
}return 0;
}

You might also like