package com.cts.elt.sort;
import java.util.Arrays;
public class SelectSort {
private int[] arr;
public void sort(){
for (int i =0;i<arr.length;i++){
for (int j=i;j<arr.length;j++){
if (arr[i]>arr[j])
swap(i,j);
}
}
}
public void swap(int a,int b){
int t =arr[a];
arr[a]=arr[b];
arr[b]=t;
}
public static void main(String [] args){
SelectSort selectSort =new SelectSort();
selectSort.arr =new int[]{1,8,4,7,2};
selectSort.sort();
System.out.println(Arrays.toString(selectSort.arr));
}
}
网友评论