Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Created February 17, 2016 13:35
Show Gist options
  • Save 78526Nasir/15a21885500d2ccd772b to your computer and use it in GitHub Desktop.
Save 78526Nasir/15a21885500d2ccd772b to your computer and use it in GitHub Desktop.
Insertion Sort implementation in C using Array !
/// Insertion Sort ///
#include<stdio.h>
main()
{
int a[100],i,value,hole,n;
printf("Enter how many elements on your Array :");
scanf("%d",&n);
printf("\nEnter %d values :",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nInsertion Sort");
for(i=0;i<n;i++)
{
value=a[i];
hole=i;
while(hole>0 && a[hole-1]>value)
{
a[hole]=a[hole-1];
hole--;
}
a[hole]=value;
}
printf("\n\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment