Last active
February 23, 2020 07:52
-
-
Save vicegd/2f3c41d8ae3a8115b00da0220405aa1a to your computer and use it in GitHub Desktop.
Sorting algorithm: Bubble method
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 void sort(int[] elements) { | |
for (int i = 1; i < elements.length; i++) { | |
for (int j = elements.length - 1; j >= i; j--) { | |
if (elements[j-1] > elements[j]){ | |
int temp = elements[j]; | |
elements[j] = elements[j-1]; | |
elements[j-1] = temp; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment