import java.util.Arrays;
//选择排序
public class selectSort {
public static void main(String[] args) {
int [] nums = {5,88,9,13,24,3,6,1};
System.out.println(Arrays.toString(nums));
for (int i = 0; i < nums.length-1; i++) {
int index = i;
for (int j = i+1; j < nums.length; j++) {
if (nums[index] > nums[j]){
index = j;
}
}
if(index != i){
int temp = nums[index];
nums[index] = nums[i];
nums[i] = temp;
}
}
System.out.println(Arrays.toString(nums));
}
}
选择排序
最新推荐文章于 2024-08-15 14:47:41 发布