Skip to content

Instantly share code, notes, and snippets.

@vicegd
Last active February 23, 2020 07:52
Show Gist options
  • Save vicegd/2f3c41d8ae3a8115b00da0220405aa1a to your computer and use it in GitHub Desktop.
Save vicegd/2f3c41d8ae3a8115b00da0220405aa1a to your computer and use it in GitHub Desktop.
Sorting algorithm: Bubble method
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