Created
August 23, 2016 02:31
-
-
Save oskimura/b1bfdea89605ca2b7d30abb87aae1f2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#include <stdio.h> | |
void p(int *array,int n) | |
{ | |
for (int i=0;i<n;i++) { | |
printf("%d ",array[i]); | |
} | |
printf("\n"); | |
} | |
void insertionSort(int *array, int n) | |
{ | |
p(array,n); | |
for (int i=1;i<n;i++) { | |
int v = array[i]; | |
int j = i -1; | |
while (j>=0 && array[j]>v) { | |
array[j+1] = array[j]; | |
j--; | |
} | |
array[j+1] = v; | |
p(array,n); | |
} | |
} | |
using namespace std; | |
const int n = 5; | |
int main() | |
{ | |
int cnt; | |
scanf("%d",&cnt); | |
int a[100]; | |
for (int i=0;i<cnt;i++){ | |
int m; | |
scanf("%d",&m); | |
a[i] = m; | |
} | |
insertionSort(a,cnt); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment