Created
February 23, 2020 07:56
-
-
Save vicegd/d4f43207668a822e8e707ddfa234c03a to your computer and use it in GitHub Desktop.
Sorting algorithm: Direct insertion method
This file contains hidden or 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 void sort(int[] elements) { | |
int j; | |
int pivot; | |
for (int i = 1; i < elements.length; i++) { | |
pivot = elements[i]; | |
j = i-1; | |
while (j >= 0 && pivot < elements[j]) { | |
elements[j+1] = elements[j]; | |
j--; | |
} | |
elements[j+1] = pivot; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment