码迷,mamicode.com
首页 > 编程语言 > 详细

选择排序

时间:2019-03-16 18:09:20      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:[]   str   来替   static   style   rgs   ++   length   .com   

public class XuanZePaiXv {
    public static void main(String[] args) {
        int[] shu=new int[]{354,687,3468,54,723,1,86};
        for (int i=0;i<shu.length-1;i++){
            for (int j=i+1;j<shu.length;j++){
                if (shu[i]>shu[j]){
                    int temp=shu[j];
                    shu[j]=shu[i];
                    shu[i]=temp;
                }
            }
        }
        for (int i=0; i <shu.length;i++){
            System.out.println(shu[i]);
        }
    }

 }

 

技术图片

通过j和i之后的数进行比较,较大的来替换第i个数的方式来排序

技术图片

选择排序

标签:[]   str   来替   static   style   rgs   ++   length   .com   

原文地址:https://www.cnblogs.com/KeepCalmAndNeverSayNever/p/10543349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!