Skip to content

Instantly share code, notes, and snippets.

@petomalina
Created January 18, 2015 14:12
Show Gist options
  • Save petomalina/d844272c5d080944d497 to your computer and use it in GitHub Desktop.
Save petomalina/d844272c5d080944d497 to your computer and use it in GitHub Desktop.
Simple Insertion sort
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