Skip to content

Instantly share code, notes, and snippets.

@agustarc
Created December 21, 2016 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agustarc/44e031a6cf2f73479ea2925d5748fb15 to your computer and use it in GitHub Desktop.
Save agustarc/44e031a6cf2f73479ea2925d5748fb15 to your computer and use it in GitHub Desktop.
public class InsertionSort {
public static void insertionSort(int[] arr) {
final int length = arr.length;
for (int i = 1; i < length; i++) {
final int key = arr[i];
int position = i;
while (position > 0 && key < arr[position - 1]) {
arr[position] = arr[position - 1];
position--;
}
arr[position] = key;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment