Created
April 13, 2015 14:01
-
-
Save bIgBV/8a04a759140420c96a77 to your computer and use it in GitHub Desktop.
When insertion goes wrong..
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
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