Skip to content

Instantly share code, notes, and snippets.

@metallurgix
Created July 13, 2014 21:24
Show Gist options
  • Save metallurgix/543128af13e32620554b to your computer and use it in GitHub Desktop.
Save metallurgix/543128af13e32620554b to your computer and use it in GitHub Desktop.
Bubble Sort
public class BubbleSort
{
private static int[] a;
private static int n;
public static void sort(int[] b)
{
a=b;
n=a.length;
bubblesort();
}
private static void bubblesort()
{
int j, t,swap=1;
int i=n;
while(i-- && swap)
{
for (j=0; j<n-1; j++)
{
swap=0;
if a[j]>a[j+1]
{
swap=1;
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