Created
May 18, 2014 14:37
-
-
Save kimitoboku/5d331eddba0f40add5fc to your computer and use it in GitHub Desktop.
intertionsort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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