Created
January 18, 2015 14:12
-
-
Save petomalina/d844272c5d080944d497 to your computer and use it in GitHub Desktop.
Simple Insertion sort
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 swap(int *a, int *b) { | |
int temp = *a; | |
*a = *b; | |
*b = temp; | |
} | |
int *insertionSort(int *array, int count) { | |
for(int i = 1; i < count; i++) { // start at the second element | |
int replacer = i; | |
while(replacer > 0 && array[replacer] < array[replacer-1]) { | |
swap(&array[replacer], &array[replacer-1]); | |
replacer--; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment