Skip to content

Instantly share code, notes, and snippets.

@pnispel
Created September 3, 2014 01:08
Show Gist options
  • Save pnispel/00da7df9be77a613e30e to your computer and use it in GitHub Desktop.
Save pnispel/00da7df9be77a613e30e to your computer and use it in GitHub Desktop.
insertion sort
int * sort (int arr [], int len) {
for (int i = 1; i < len; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment