Skip to content

Instantly share code, notes, and snippets.

@lifeparticle
Last active May 23, 2021 10:59
Show Gist options
  • Save lifeparticle/41a7861eaf32db44dca4f76f363be927 to your computer and use it in GitHub Desktop.
Save lifeparticle/41a7861eaf32db44dca4f76f363be927 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) {
int i, j;
int tmp = 0;
for (i = 0; i < arr.length; ++i) {
for (j = 0; j < arr.length - 1; ++j) {
if (arr [j] > arr [j + 1]) {
tmp = arr [j];
arr [j] = arr [j + 1];
arr [j + 1] = tmp;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment