简单记录一下选择排序

/**
* ClassName SelectionSort.java
* author 舒一笑
* version 1.0.0
* Description 选择排序代码实现类
* createTime 2024年01月17日 22:06:00
*/
public class SelectionSort {
public static void selectionSort(int[] arr) {
if (arr == null || arr.length < 2){
return
}
for (int i = 0
int minIndex = i
for (int j = i + 1
if (arr[j] < arr[minIndex]) {
minIndex = j
}
}
swap(arr, i, minIndex)
}
}
public static void swap(int[] arr, int i, int j) {
int temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
}
public static void main(String[] args) {
int[] arr = new int[]{10, 8 ,3 , 5 , 7 , 1}
for (int i = 0
System.out.print(arr[i] + " ")
}
System.out.println()
selectionSort(arr)
for (int i = 0
System.out.print(arr[i] + " ")
}
}
}
```
```