Skip to content

Instantly share code, notes, and snippets.

@ckob
Created December 15, 2015 10:55
Show Gist options
  • Select an option

  • Save ckob/6f7694ff320c867136db to your computer and use it in GitHub Desktop.

Select an option

Save ckob/6f7694ff320c867136db to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class bubble {
public static void main (String args[]) {
int[] n = {900, 5, 9, 4, 3, 7, 13, 5, 1, 80, 90, 40, 60, 10, -54, 10, 2, -9090};
System.out.println(Arrays.toString(n));
System.out.println(Arrays.toString(bubble(n)));
}
public static int[] bubble (int n[]) {
int tmp, l = n.length;
for (int i=l;i>0;i--) {
for (int x=0;x<l-1;x++) {
if (n[x] > n[x+1]) {
tmp = n[x];
n[x] = n[x+1];
n[x+1] = tmp;
}
}
}
return n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment