Created
December 15, 2015 10:55
-
-
Save ckob/6f7694ff320c867136db to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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