冒泡排序
import java.util.Arrays;
public class BubbleSort {
public static void sort(int[] array) {
for(int i = 0; i < array.length - 2; ++i) {
for(int j = array.length - 1; j > i; --j) {
if(array[j] < array[j-1]) {
int temp = array[j];
array[j] = array[j-1];
array[j-1] = temp;
}
}
}
}
public static void main(String[] args) {
int[] test = {1, 5, 3, 9, 15, 20, 2, 6};
BubbleSort.sort(test);
System.out.println(Arrays.toString(test));
int[] c = {};
BubbleSort.sort(c);
System.out.println(Arrays.toString(c));
}
}