阅读背景:

iOS疯狂详解之排序(选择排序/插入排序)

来源:互联网 

选择排序

 1.先求最小值

 2.找到地位

 3.把地位的数放到有序区

 4.反复

    for (int j = 0; j < count - 1; j++) {
        
        int minIndex = j;//  最小值的角标
        
        for (int i = minIndex + 1; i < count; i++) {
            
            if (array[minIndex] > array[i]) {
                minIndex = i;
            }
            
        }
        
        if (minIndex != j) {  //  优化 无序区的头 不是第一个 
            
            //  最小值 放入头部
            int temp;
            temp = array[minIndex];
            array[minIndex] = array[j];
            array[j] = temp;
            
        }
        
    }
 




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: