Created
July 13, 2014 21:24
-
-
Save metallurgix/543128af13e32620554b to your computer and use it in GitHub Desktop.
Bubble Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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