码迷,mamicode.com
首页 > 其他好文 > 详细

bubble sort

时间:2018-06-07 22:59:49      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:sort   bsp   spl   个人   parse   oid   ble   简单   ring   

public class bubbleSort {
    public static void main(String[] args) {
        while(true){
        System.out.println("请输入数组,以空格分割,以回车键结束");
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] strs = str.split(" ");
        int[] arrs = new int[strs.length];
        for (int i=0;i<strs.length;i++) {
            arrs[i] = Integer.parseInt(strs[i]);
        }
        int temp = 0;
        for (int i = 0; i < arrs.length-1; i++) {
            for (int j = i+1; j < arrs.length; j++) {
                if(arrs[j]>arrs[i]){
                    temp = arrs[i];
                    arrs[i] = arrs[j];
                    arrs[j] = temp;
                }
            }
        }
        System.out.println("从大到小排序:");
        for (int i : arrs) {
            System.err.print(i+" ");
        }
        System.out.println();
        }
    }
}

学习之余,写个简单的冒泡排序,纯属个人娱乐

bubble sort

标签:sort   bsp   spl   个人   parse   oid   ble   简单   ring   

原文地址:https://www.cnblogs.com/syd-fish-cat/p/9152916.html

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