package com.company;
import java.util.Arrays;
/**
* @date on 2020/6/18 16:15
* @author longlyboyhe
* @filename SelectSort.java
* @description 选择排序
*/
public class SelectSort {
public void selectSort(int[] array){
int length=array.length;
for(int i=0;i<length-1;i++){
int index=i;
int j;
for(j=i+1;j<length;j++){
if(array[j]<array[index]){
index=j;
}
}
int temp=array[index];
array[index]=array[i];
array[i]=temp;
System.out.println(Arrays.toString(array));
}
}
public static void main(String[] args) {
SelectSort selectSort=new SelectSort();
selectSort.selectSort(new int[]{49,38,65,97,76,13,27,49});
}
}
运行结果: