Skip to content

Instantly share code, notes, and snippets.

@kimitoboku
Created May 18, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimitoboku/5d331eddba0f40add5fc to your computer and use it in GitHub Desktop.
Save kimitoboku/5d331eddba0f40add5fc to your computer and use it in GitHub Desktop.
intertionsort
#include<stdio.h>
void insertionsort(int array[],int n){
int i;
for(i=1;i<n;i++){
int k = array[i];
int j = i -1;
while((j>=0)&&(array[j] > k)){
array[j+1] = array[j];
j--;
}
array[j+1] = k;
}
}
int main(void){
int array[100];
int n;
scanf("%d",&n);
int i;
for(i=0;i<n;i++){
scanf("%d",&array[i]);
}
insertionsort(array,n);
for(i=0;i<n;i++){
printf("%d ",array[i]);
}
puts("");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment