Skip to content

Instantly share code, notes, and snippets.

@developer-sdk
Created June 8, 2016 13:31
Show Gist options
  • Save developer-sdk/f21777d37f7b13048c6068b9f9d22975 to your computer and use it in GitHub Desktop.
Save developer-sdk/f21777d37f7b13048c6068b9f9d22975 to your computer and use it in GitHub Desktop.
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