package com.sort;
public class SelectSort {
public static void main(String[] args) {
int[] a = new int[]{6,5,4,3,2,1};
selectSort(a);
for(int array:a){
System.out.println(array);
}
}
private static void selectSort(int[] a) {
for(int i=0; i<a.length; i++){
int index = i;
for(int j=i; j<a.length; j++){
if(a[index]>a[j]){
index = j;
}
}
swap(a,i,index);
}
}
private static void swap(int[] a, int j, int i) {
int temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
简单选择排序
最新推荐文章于 2023-03-08 16:45:09 发布
本文介绍了一个简单的选择排序算法实现。通过示例代码展示了如何对整数数组进行升序排列,并提供了详细的排序过程说明。

198

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



