美文网首页
选择排序

选择排序

作者: uin_sisyphus | 来源:发表于2018-10-31 16:36 被阅读0次
    选择排序.png
        public static void SelectSort(int[] a){
            int n = a.length;
            int i,j,k;
            int temp;
            for(i=0; i< n; i++){
                //k用来记录一趟的最小值
                k=i;
                for(j=i+1; j<n; j++){
                    if(a[k] > a[j]){
                        k=j;
                    }
                }
                //交换
                temp =a[i];
                a[i]= a[k];
                a[k]= temp;
                
            }
        }
    

    相关文章

      网友评论

          本文标题:选择排序

          本文链接:https://www.haomeiwen.com/subject/tzmgtqtx.html