public class BubbleSortDemo {
public static void main(String[] args) {
int[] ints = {5,9,6,4,3,5,8,1,2,4};
sort(ints);
for (int i : ints) {
System.out.print(i + " ");
}
}
public static void sort(int[] array) {
int tmp;
for (int i = array.length - 1; i >= 1; i--) {
for (int j = 0; j < i; j++) {
if (array[j] > array[j + 1]) {
tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}
}
}原文地址:http://pengsaiwei.blog.51cto.com/3071802/1745401