Skip to content

Instantly share code, notes, and snippets.

@lifeparticle
Last active May 23, 2021 10:59
Show Gist options
  • Save lifeparticle/538d9489daa5bc0cdffeba3dd761d769 to your computer and use it in GitHub Desktop.
Save lifeparticle/538d9489daa5bc0cdffeba3dd761d769 to your computer and use it in GitHub Desktop.
public class Main {
public static void main (String args[]) {
bubbleSort(new int [] {1, 4, 7, 10, 2});
}
public static void bubbleSort(int[] arr) {
boolean isSorted = false;
int j = 1, i;
int tmp;
while (!isSorted) {
isSorted = true;
for (i = 0; i < arr.length - j; ++i) {
if (arr [i] > arr [i + 1]) {
tmp = arr [i];
arr [i] = arr [i + 1];
arr [i + 1] = tmp;
isSorted = false;
}
}
j++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment