Skip to content

Instantly share code, notes, and snippets.

@ckob
Created December 14, 2015 19:42
Show Gist options
  • Select an option

  • Save ckob/21ec6e553b52b0f7a2c4 to your computer and use it in GitHub Desktop.

Select an option

Save ckob/21ec6e553b52b0f7a2c4 to your computer and use it in GitHub Desktop.
public static void bubble () {
int[] n = {5, 9, 4, 3, 7, 13, 5, 1};
System.out.println(Arrays.toString(n));
int l = n.length;
int f = l-1;
int tmp = 0;
for (int i=l;i>0;i--) {
for (int x=0;x<f;x++) {
if (n[x] > n[x+1]) {
tmp = n[x];
n[x] = n[x+1];
n[x+1] = tmp;
}
}
}
System.out.println(Arrays.toString(n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment