Created
January 14, 2013 23:06
-
-
Save RicardoMurad/4534401 to your computer and use it in GitHub Desktop.
Bobble sort in java
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
| 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