Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created August 23, 2016 02:31
Show Gist options
  • Save oskimura/b1bfdea89605ca2b7d30abb87aae1f2c to your computer and use it in GitHub Desktop.
Save oskimura/b1bfdea89605ca2b7d30abb87aae1f2c to your computer and use it in GitHub Desktop.
#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