排序算法
冒泡排序
public static int[] sort(int[] a) {
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
return a;
}
插入排序
public static int[] insertSort(int[] b) {
for (int i = 1; i < b.length; i++) {
for (int j = i; j > 0 && b[j] < b[j - 1]; j--) {
int min = b[j];
b[j] = b[j-1];
b[j-1] = min;
}
}
return b;
}