public class Sort {
public static void main(String[] args) {
int[] arr = { 24, 69, 80, 57, 13 };
bubbleSort(arr);
selectSort(arr);
for (int s : arr) {
System.out.print(s + "/");
}
}
//冒泡排序
public static void bubbleSort(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int a = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = a;
}
}
}
}
//选择排序
public static void selectSort(int[] arr){
for (int i = 0; i < arr.length - 1; i++) {
for (int j = i+1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
int a = arr[i];
arr[i] = arr[j];
arr[j] = a;
}
}
}
}
}