package com.kilophone.classcontent;
// 原理:每一趟从待排序的记录中选出最小的元素,
// 顺序放在已排好序的序列最后,直到全部记录排序完毕
public class TestSelectSort {
public static void main(String[] args) {
int arr[] = { 15, 23, 7, 10, 8 };
for (int i = 0; i < arr.length - 1; i++) {
int k = i;
for (int j = k + 1; j < arr.length; j++) {
if (arr[k] > arr[j]) {
k = j;
}
}
if (i != k) {
int temp;
temp = arr[k];
arr[k] = arr[i];
arr[i] = temp;
}
}
for (int a : arr) {
System.out.println(a);
}
}
}
SelectSort,选择排序
最新推荐文章于 2020-08-05 14:22:10 发布