Skip to content

Instantly share code, notes, and snippets.

@rohit-nsit08
Created September 2, 2011 16:32
Show Gist options
  • Select an option

  • Save rohit-nsit08/1189087 to your computer and use it in GitHub Desktop.

Select an option

Save rohit-nsit08/1189087 to your computer and use it in GitHub Desktop.
simple insertion sort
//insertion sort
#include<stdio.h>
int main()
{
int arr[5]={5,4,3,2,1};
int i,j,chose;
int n = sizeof(arr)/sizeof(int);
for(i=1;i<n;i++)
{
chose = arr[i]; // chose the ith card
j=i-1;
while((j>=0)&&(arr[j]>chose))
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = chose;
}
for(i=0;i<n;i++)
printf("%d ",arr[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment