其他分享
首页 > 其他分享> > 选择排序

选择排序

作者:互联网

选择排序

代码实现

public class Solution {
    
    public void selectSort(int[] arr) {
        int len = arr.length;
        for (int i = 0; i < len; i++) {
            int minIndex = i;
            for (int j = i + 1; j < len; j++) {
                minIndex = arr[minIndex] > arr[j] ? j : minIndex;
            }
//            交换两个元素
            int temp = arr[minIndex];
            arr[minIndex] = arr[i];
            arr[i] = temp;
            
        }
        
    }
}

标签:minIndex,arr,int,len,选择,序列,排序
来源: https://www.cnblogs.com/mightcell/p/16374531.html