Skip to content

Instantly share code, notes, and snippets.

@bIgBV
Created April 13, 2015 14:01
Show Gist options
  • Save bIgBV/8a04a759140420c96a77 to your computer and use it in GitHub Desktop.
Save bIgBV/8a04a759140420c96a77 to your computer and use it in GitHub Desktop.
When insertion goes wrong..
void insertion_sort(int list[], int length)
{
int j = 1;
int key = list[j];
std::cout << key << std::endl;
while(j < length)
{
int i = j - 1;
while(i >=0 && list[i] > key)
{
list[i + 1 ] = list[i];
--i;
}
list[i + 1] = key;
j++;
// Priting infomation for debugging
for(int i = 0; i < 10; i++)
{
std::cout << list[i] << ", ";
}
std::cout << std::endl;
}
for(int i = 0; i < 10; i++)
{
std::cout << list[i] << ", ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment