Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created August 26, 2012 20:32
Show Gist options
  • Save fsouza/3483418 to your computer and use it in GitHub Desktop.
Save fsouza/3483418 to your computer and use it in GitHub Desktop.
#include <iostream>
void
insertion(int v[], int size)
{
int aux;
for(int i = 0; i < size-1; i++) {
for(int j = i+1; j >= 0 && v[j] < v[j-1]; j--) {
aux = v[j-1];
v[j-1] = v[j];
v[j] = aux;
}
}
}
int
main(void)
{
int v[] = {5, 4, 2, 10, 30, 8};
insertion(v, 6);
for(int i = 0; i < 6; i++) {
std::cout << v[i] << " ";
}
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment