Created
June 8, 2016 13:31
-
-
Save developer-sdk/f21777d37f7b13048c6068b9f9d22975 to your computer and use it in GitHub Desktop.
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
package sdk.java.sort; | |
public class BubbleSort { | |
public static void main(String[] args) { | |
int[] array = { 4, 3, 2, 5, 6, 19, 23, 5, 18, 28, 8 }; | |
sort(array); | |
for(int a : array) { | |
System.out.format("%d ", a); | |
} | |
} | |
public static void sort(int[] array) { | |
for(int i = 0; i < array.length; i++) { | |
for(int j = 0; j < array.length - 1; j++) { | |
if(array[j] > array[j+1]) { | |
int temp = array[j]; | |
array[j] = array[j+1]; | |
array[j+1] = temp; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment