/**
* 选择排序。
* @author Bright Lee
*/
public class SelectionSort {
public static void sort(int[] array) {
for (int i = 0; i < array.length; i++) {
int minIndex = i;
for (int j = i + 1; j < array.length; j++) {
if (array[j] <= array[minIndex]) {
minIndex = j;
}
}
int temp = array[i];
array[i] = array[minIndex];
array[minIndex] = temp;
}
}
public static void main(String[] args) {
int[] array = new int[] {
13, 2, 29, 11, 80, 1, 12, 11
};
sort(array);
for (int i = 0; i < array.length; i++) {
int a = array[i];
System.out.print(a + ", ");
}
}
}
榴芒客服系统:https://blog.youkuaiyun.com/look4liming/article/details/83146776
本文深入讲解了选择排序算法的实现原理及步骤,通过一个具体的Java代码示例展示了如何使用选择排序对整数数组进行排序。文章包括了算法的详细解释、代码实现以及运行结果展示。

被折叠的 条评论
为什么被折叠?



