?视频讲解地址:【手把手带你写十大排序】4.选择排序(Java语言)_哔哩哔哩_bilibili
代码:
public class SelectSort {
public void swap(int[] array, int index1, int index2){
array[index1] = array[index1] ^ array[index2];
array[index2] = array[index1] ^ array[index2];
array[index1] = array[index1] ^ array[index2];
}
public void sortFunction(int[] array) {
for (int i = 0; i < array.length - 1; i++) {
int minNumIndex = i;
for (int j = i + 1; j < array.length; j++) {
if (array[j] < array[minNumIndex]) {
minNumIndex = j;
}
}
if (minNumIndex != i){
swap(array, minNumIndex, i);
}
}
}
}