Created
December 21, 2016 19:51
-
-
Save agustarc/44e031a6cf2f73479ea2925d5748fb15 to your computer and use it in GitHub Desktop.
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
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