Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

介绍

选择排序算法是最简单的排序算法,通过循环的方式每次取剩余蒜素中最大最小值,与指针当前所指位置的元素交换位置,之后指针后移,再次重复操作…

代码实现

public class SelectionSort{
    public static <E extend Comparable<E>> void doSort(E[],arr){
        E temp;
        for (int i = 0; i < arr.length; i++){
            for (int j = i + 1; j < arr.length; j++){
                if (arr[i].compareTo(arr[j]) > 0){
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
                }
            }
        }
    }
}