Skip to content

Instantly share code, notes, and snippets.

@RicardoMurad
Created January 14, 2013 23:06
Show Gist options
  • Select an option

  • Save RicardoMurad/4534401 to your computer and use it in GitHub Desktop.

Select an option

Save RicardoMurad/4534401 to your computer and use it in GitHub Desktop.
Bobble sort in java
package com.foo.bar;
import java.util.Arrays;
public class BubbleSort {
public static void main(String a[]) {
int array[] = { 12, 9, 4, 99, 120, 1, 3, 10 };
System.out.println(Arrays.toString(array));
sort(array);
System.out.println(Arrays.toString(array));
}
public static void sort(int a[]) {
int i, j, t = 0;
for (i = 0; i < a.length -1; i++) {
for (j = 1; j < (a.length - i); j++) {
if (a[j - 1] > a[j]) {
t = a[j - 1];
a[j - 1] = a[j];
a[j] = t;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment